Я вызываю хранимую процедуру rpt_legder_transaction
в цикле, как показано ниже:
$records = array();
foreach($importUtility->post_data as $arr)
{
$conditions = array(
"_from_legder_account_id" => $legder_account_list[$arr['ledger_account']],
"_from_date" => $arr['_from_date'],
"_to_date" => $arr['_to_date'],
);
$data = $this->{$this->modelClass}->rpt_legder_transaction($conditions);
$total_current = 0;
foreach($data["current"] as $current)
{
$total_current += $current['amount'];
}
$data["total_current"] = $total_current;
$data["conditions"] = $arr;
$records[] = $data;
}
Я использую версию cakephp 2.x, поэтому я получаю результат при первом вызове
app/Model/LegderAccount.php (line 111)
array(
(int) 0 => array(
'LegderTransaction' => array(
'id' => '8369',
'refer_legder_transaction_id' => '8368',
'from_legder_account_id' => '30',
'to_legder_account_id' => '276',
'legder_voucher_type_id' => '1',
'voucher_no' => 'E-662',
'legder_payment_id' => null,
'legder_reciept_id' => '511',
'legder_expense_id' => null,
'legder_sale_id' => null,
'datetime' => '2019-10-25 18:42:12',
'amount' => '-40',
'comments' => 'Sample Courier',
'created' => '2019-10-25 18:42:12',
'created_by' => '112',
'modified' => '2019-10-25 20:27:12',
'modified_by' => '89'
),
'LegderVoucherType' => array(
'id' => '1',
'basic_voucher_type' => '1',
'name' => 'Payment',
'inventory_type' => '1',
'is_default' => true,
'is_system' => false,
'created' => '2018-10-22 11:48:42',
'created_by' => '1',
'modified' => '2018-10-25 17:37:54',
'modified_by' => '1'
),
'la' => array(
'id' => '30',
'legder_group_id' => '0',
'code' => '',
'type' => '2',
'user_id' => '112',
'location_id' => '0',
'opening_balance' => '0',
'is_virtual' => false,
'is_primary' => false,
'is_admin' => false,
'is_supplier' => false,
'created' => '2019-06-15 17:34:08'
),
'lg' => array(
'legder_group' => null
),
**'FromLegderAccount'** => array(
'name' => 'Mohd Anis-112',
'is_active' => '1'
),
**'ToLegderAccount'** => array(
'id' => '276',
'legder_group_id' => '8',
'code' => '',
'type' => '1',
'user_id' => '0',
'location_id' => '0',
'opening_balance' => '0',
'is_virtual' => false,
'is_primary' => false,
'is_admin' => false,
'is_supplier' => false,
'created' => '2019-09-06 17:13:03',
'legder_group' => 'labour-job work expenses-non itemised',
'name' => 'Other misceallanous jobs',
'is_active' => '1'
),
'LegderPayment' => array(
'id' => null,
'from_legder_account_id' => null,
'to_legder_account_id' => null,
'legder_voucher_type_id' => null,
'voucher_no' => null,
'amount' => null,
'comments' => null,
'is_verified' => null,
'verify_by' => null,
'is_deleted' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderReciept' => array(
'id' => '511',
'from_legder_account_id' => '276',
'to_legder_account_id' => '30',
'legder_voucher_type_id' => '2',
'voucher_no' => 'E-662',
'amount' => '40',
'comments' => 'Sample Courier',
'is_verified' => true,
'verify_by' => '89',
'is_deleted' => false,
'created' => '2019-10-25 18:42:12',
'created_by' => '112',
'modified' => '2019-10-25 20:27:12',
'modified_by' => '89'
),
'LegderExpense' => array(
'id' => null,
'type' => null,
'from_legder_account_id' => null,
'to_legder_account_id' => null,
'legder_voucher_type_id' => null,
'legder_type_id' => null,
'inventory_id' => null,
'party_voucher_no' => null,
'voucher_no' => null,
'amount' => null,
'expect_amount' => null,
'comments' => null,
'mobile_no' => null,
'image' => null,
'is_verified' => null,
'verify_by' => null,
'sale_id' => null,
'have_item' => null,
'is_deleted' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpenseImage' => array(
'id' => null,
'legder_expense_id' => null,
'image' => null,
'created' => null,
'created_by' => null
),
'LegderExpenseDetail' => array(
'id' => null,
'legder_expense_id' => null,
'type' => null,
'item_id' => null,
'product_id' => null,
'inventory_detail_id' => null,
'qty' => null,
'rate' => null,
'amount' => null,
'is_deleted' => null,
'created' => null,
'modified' => null
),
'LegderExpenseProduct' => array(
'id' => null,
'name' => null,
'sku' => null
),
'LegderExpenseCategory' => array(
'id' => null,
'parent_id' => null,
'name' => null,
'details' => null,
'code' => null,
'uom_id' => null,
'sku_pattern' => null,
'field_style' => null,
'field_color' => null,
'field_size' => null,
'gst_per' => null,
'length' => null,
'width' => null,
'height' => null,
'weight' => null,
'size_chart' => null,
'is_finish_good' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpenseProductFile' => array(
'id' => null,
'product_id' => null,
'image_id' => null,
'is_primary' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpenseProductFileImage' => array(
'id' => null,
'photoshoot_variation_id' => null,
'name' => null,
'original' => null,
'image' => null,
'thumbnail' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpenseItem' => array(
'id' => null,
'name' => null,
'uom_id' => null,
'image' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSale' => array(
'id' => null,
'type' => null,
'from_legder_account_id' => null,
'to_legder_account_id' => null,
'legder_voucher_type_id' => null,
'legder_type_id' => null,
'inventory_id' => null,
'voucher_no' => null,
'amount' => null,
'expect_amount' => null,
'comments' => null,
'mobile_no' => null,
'image' => null,
'is_verified' => null,
'verify_by' => null,
'expense_id' => null,
'have_item' => null,
'is_deleted' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSaleImage' => array(
'id' => null,
'legder_sale_id' => null,
'image' => null,
'created' => null,
'created_by' => null
),
'LegderSaleDetail' => array(
'id' => null,
'legder_sale_id' => null,
'type' => null,
'item_id' => null,
'product_id' => null,
'inventory_detail_id' => null,
'qty' => null,
'rate' => null,
'amount' => null,
'is_deleted' => null,
'created' => null,
'modified' => null
),
'LegderSaleProduct' => array(
'id' => null,
'name' => null,
'sku' => null
),
'LegderSaleCategory' => array(
'id' => null,
'parent_id' => null,
'name' => null,
'details' => null,
'code' => null,
'uom_id' => null,
'sku_pattern' => null,
'field_style' => null,
'field_color' => null,
'field_size' => null,
'gst_per' => null,
'length' => null,
'width' => null,
'height' => null,
'weight' => null,
'size_chart' => null,
'is_finish_good' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSaleProductFile' => array(
'id' => null,
'product_id' => null,
'image_id' => null,
'is_primary' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSaleProductFileImage' => array(
'id' => null,
'photoshoot_variation_id' => null,
'name' => null,
'original' => null,
'image' => null,
'thumbnail' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSaleItem' => array(
'id' => null,
'name' => null,
'uom_id' => null,
'image' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
)
),
)
Я получил этот результат, когда был сделан второй вызов:
app/Model/LegderAccount.php (line 111)
array(
(int) 0 => array(
'LegderTransaction' => array(
'id' => '7673',
'refer_legder_transaction_id' => '0',
'from_legder_account_id' => '161',
'to_legder_account_id' => '27',
'legder_voucher_type_id' => '9',
'voucher_no' => 'P-998',
'legder_payment_id' => null,
'legder_reciept_id' => null,
'legder_expense_id' => null,
'legder_sale_id' => null,
'datetime' => '2019-10-19 10:15:34',
'amount' => '28031',
'comments' => 'Paid Salary',
'created' => '2019-10-19 10:15:34',
'created_by' => '90',
'modified' => '2019-10-19 10:15:34',
'modified_by' => '90'
),
'LegderVoucherType' => array(
'id' => '9',
'basic_voucher_type' => '1',
'name' => 'Salary',
'inventory_type' => '2',
'is_default' => false,
'is_system' => false,
'created' => '2019-06-13 10:00:49',
'created_by' => '1',
'modified' => '2019-06-13 10:00:49',
'modified_by' => '1'
),
'la' => array(
'id' => '161',
'legder_group_id' => '0',
'code' => '',
'type' => '2',
'user_id' => '235',
'location_id' => '0',
'opening_balance' => '0',
'is_virtual' => false,
'is_primary' => false,
'is_admin' => false,
'is_supplier' => false,
'created' => '2019-07-13 12:31:30'
),
'lg' => array(
'legder_group' => null
),
'view_legder_accounts' => array(
'name' => 'Salary',
'is_active' => '1',
'id' => '27',
'legder_group_id' => '0',
'code' => 'Salary_Account',
'type' => '1',
'user_id' => '0',
'location_id' => '0',
'opening_balance' => '0',
'is_virtual' => true,
'is_primary' => false,
'is_admin' => false,
'is_supplier' => false,
'created' => '2019-06-15 15:13:50',
'legder_group' => null
),
'LegderPayment' => array(
'id' => null,
'from_legder_account_id' => null,
'to_legder_account_id' => null,
'legder_voucher_type_id' => null,
'voucher_no' => null,
'amount' => null,
'comments' => null,
'is_verified' => null,
'verify_by' => null,
'is_deleted' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderReciept' => array(
'id' => null,
'from_legder_account_id' => null,
'to_legder_account_id' => null,
'legder_voucher_type_id' => null,
'voucher_no' => null,
'amount' => null,
'comments' => null,
'is_verified' => null,
'verify_by' => null,
'is_deleted' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpense' => array(
'id' => null,
'type' => null,
'from_legder_account_id' => null,
'to_legder_account_id' => null,
'legder_voucher_type_id' => null,
'legder_type_id' => null,
'inventory_id' => null,
'party_voucher_no' => null,
'voucher_no' => null,
'amount' => null,
'expect_amount' => null,
'comments' => null,
'mobile_no' => null,
'image' => null,
'is_verified' => null,
'verify_by' => null,
'sale_id' => null,
'have_item' => null,
'is_deleted' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpenseImage' => array(
'id' => null,
'legder_expense_id' => null,
'image' => null,
'created' => null,
'created_by' => null
),
'LegderExpenseDetail' => array(
'id' => null,
'legder_expense_id' => null,
'type' => null,
'item_id' => null,
'product_id' => null,
'inventory_detail_id' => null,
'qty' => null,
'rate' => null,
'amount' => null,
'is_deleted' => null,
'created' => null,
'modified' => null
),
'LegderExpenseProduct' => array(
'id' => null,
'name' => null,
'sku' => null
),
'LegderExpenseCategory' => array(
'id' => null,
'parent_id' => null,
'name' => null,
'details' => null,
'code' => null,
'uom_id' => null,
'sku_pattern' => null,
'field_style' => null,
'field_color' => null,
'field_size' => null,
'gst_per' => null,
'length' => null,
'width' => null,
'height' => null,
'weight' => null,
'size_chart' => null,
'is_finish_good' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpenseProductFile' => array(
'id' => null,
'product_id' => null,
'image_id' => null,
'is_primary' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpenseProductFileImage' => array(
'id' => null,
'photoshoot_variation_id' => null,
'name' => null,
'original' => null,
'image' => null,
'thumbnail' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderExpenseItem' => array(
'id' => null,
'name' => null,
'uom_id' => null,
'image' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSale' => array(
'id' => null,
'type' => null,
'from_legder_account_id' => null,
'to_legder_account_id' => null,
'legder_voucher_type_id' => null,
'legder_type_id' => null,
'inventory_id' => null,
'voucher_no' => null,
'amount' => null,
'expect_amount' => null,
'comments' => null,
'mobile_no' => null,
'image' => null,
'is_verified' => null,
'verify_by' => null,
'expense_id' => null,
'have_item' => null,
'is_deleted' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSaleImage' => array(
'id' => null,
'legder_sale_id' => null,
'image' => null,
'created' => null,
'created_by' => null
),
'LegderSaleDetail' => array(
'id' => null,
'legder_sale_id' => null,
'type' => null,
'item_id' => null,
'product_id' => null,
'inventory_detail_id' => null,
'qty' => null,
'rate' => null,
'amount' => null,
'is_deleted' => null,
'created' => null,
'modified' => null
),
'LegderSaleProduct' => array(
'id' => null,
'name' => null,
'sku' => null
),
'LegderSaleCategory' => array(
'id' => null,
'parent_id' => null,
'name' => null,
'details' => null,
'code' => null,
'uom_id' => null,
'sku_pattern' => null,
'field_style' => null,
'field_color' => null,
'field_size' => null,
'gst_per' => null,
'length' => null,
'width' => null,
'height' => null,
'weight' => null,
'size_chart' => null,
'is_finish_good' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSaleProductFile' => array(
'id' => null,
'product_id' => null,
'image_id' => null,
'is_primary' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSaleProductFileImage' => array(
'id' => null,
'photoshoot_variation_id' => null,
'name' => null,
'original' => null,
'image' => null,
'thumbnail' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
),
'LegderSaleItem' => array(
'id' => null,
'name' => null,
'uom_id' => null,
'image' => null,
'created' => null,
'created_by' => null,
'modified' => null,
'modified_by' => null
)
),
)
Вы можете заметить, что я получил другие результаты, FromLegderAccount
отсутствует, view_legder_accounts
появляется в наборе результатов.
Это хранимая процедура:
CREATE DEFINER=`root`@`localhost` PROCEDURE `rpt_legder_transaction`(
IN _from_legder_account_id INT,
IN _to_legder_account_id INT,
IN _legder_voucher_type_id INT,
IN _voucher_no VARCHAR(20),
IN _from_date DATE,
IN _to_date DATE,
IN _id INT
)
BEGIN
SELECT
LegderTransaction.*,
LegderVoucherType.*,
FromLegderAccount.*,
ToLegderAccount.*,
LegderPayment.*,
LegderReciept.*,
LegderExpense.*,
LegderExpenseImage.*,
LegderExpenseDetail.*,
LegderExpenseProduct.id,
LegderExpenseProduct.name,
LegderExpenseProduct.sku,
LegderExpenseCategory.*,
LegderExpenseProductFile.*,
LegderExpenseProductFileImage.*,
LegderExpenseItem.*,
LegderSale.*,
LegderSaleImage.*,
LegderSaleDetail.*,
LegderSaleProduct.id,
LegderSaleProduct.name,
LegderSaleProduct.sku,
LegderSaleCategory.*,
LegderSaleProductFile.*,
LegderSaleProductFileImage.*,
LegderSaleItem.*
FROM
legder_transactions LegderTransaction
INNER JOIN legder_voucher_types AS LegderVoucherType ON LegderVoucherType.id = LegderTransaction.legder_voucher_type_id
INNER JOIN view_legder_accounts AS FromLegderAccount ON FromLegderAccount.id = LegderTransaction.from_legder_account_id
INNER JOIN view_legder_accounts AS ToLegderAccount ON ToLegderAccount.id = LegderTransaction.to_legder_account_id
LEFT JOIN legder_payments LegderPayment ON LegderPayment.id = LegderTransaction.legder_payment_id
LEFT JOIN legder_reciepts LegderReciept ON LegderReciept.id = LegderTransaction.legder_reciept_id
LEFT JOIN legder_expenses LegderExpense ON LegderExpense.id = LegderTransaction.legder_expense_id
LEFT JOIN legder_expense_details LegderExpenseDetail ON LegderExpenseDetail.legder_expense_id = LegderExpense.id
LEFT JOIN legder_expense_images LegderExpenseImage ON LegderExpenseImage.legder_expense_id = LegderExpense.id
LEFT JOIN products LegderExpenseProduct ON LegderExpenseProduct.id = LegderExpenseDetail.product_id
LEFT JOIN categories LegderExpenseCategory ON LegderExpenseCategory.id = LegderExpenseProduct.category_id
LEFT JOIN product_files LegderExpenseProductFile ON LegderExpenseProductFile.product_id = LegderExpenseProduct.id
LEFT JOIN images LegderExpenseProductFileImage ON LegderExpenseProductFileImage.id = LegderExpenseProductFile.image_id
LEFT JOIN items LegderExpenseItem ON LegderExpenseItem.id = LegderExpenseDetail.item_id
LEFT JOIN legder_sales LegderSale ON LegderSale.id = LegderTransaction.legder_sale_id
LEFT JOIN legder_sale_details LegderSaleDetail ON LegderSaleDetail.legder_sale_id = LegderSale.id
LEFT JOIN legder_sale_images LegderSaleImage ON LegderSaleImage.legder_sale_id = LegderSale.id
LEFT JOIN products LegderSaleProduct ON LegderSaleProduct.id = LegderSaleDetail.product_id
LEFT JOIN categories LegderSaleCategory ON LegderSaleCategory.id = LegderSaleProduct.category_id
LEFT JOIN product_files LegderSaleProductFile ON LegderSaleProductFile.product_id = LegderSaleProduct.id
LEFT JOIN images LegderSaleProductFileImage ON LegderSaleProductFileImage.id = LegderSaleProductFile.image_id
LEFT JOIN items LegderSaleItem ON LegderSaleItem.id = LegderSaleDetail.item_id
WHERE
(_id IS NULL OR LegderTransaction.id = _id)
AND (_from_legder_account_id IS NULL OR LegderTransaction.from_legder_account_id = _from_legder_account_id)
AND (_to_legder_account_id IS NULL OR LegderTransaction.to_legder_account_id = _to_legder_account_id)
AND (_legder_voucher_type_id IS NULL OR LegderTransaction.legder_voucher_type_id = _legder_voucher_type_id)
AND (_voucher_no IS NULL OR LegderTransaction.voucher_no = _voucher_no)
AND (_from_date IS NULL OR _from_date <= DATE(LegderTransaction.datetime))
AND (_to_date IS NULL OR _to_date >= DATE(LegderTransaction.datetime))
ORDER BY
LegderTransaction.datetime DESC, LegderTransaction.id DESC;
END
Ниже приведен вид
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `view_legder_accounts` AS
SELECT
`la`.`id` AS `id`,
`la`.`legder_group_id` AS `legder_group_id`,
`la`.`code` AS `code`,
`la`.`type` AS `type`,
`la`.`user_id` AS `user_id`,
`la`.`location_id` AS `location_id`,
`la`.`opening_balance` AS `opening_balance`,
`la`.`is_virtual` AS `is_virtual`,
`la`.`is_primary` AS `is_primary`,
`la`.`is_admin` AS `is_admin`,
`la`.`is_supplier` AS `is_supplier`,
`la`.`created` AS `created`,
`lg`.`name` AS `legder_group`,
(CASE
WHEN
(`la`.`type` = 2)
THEN
CONCAT(TRIM(CONCAT(`u`.`firstname`, ' ', `u`.`lastname`)),
'-',
`u`.`id`)
WHEN (`la`.`type` = 3) THEN CONCAT(`l`.`name`, '-', `l`.`id`)
ELSE `la`.`name`
END) AS `name`,
(CASE
WHEN (`la`.`type` = 2) THEN `u`.`is_active`
ELSE 1
END) AS `is_active`
FROM
(((`legder_accounts` `la`
LEFT JOIN `legder_groups` `lg` ON ((`lg`.`id` = `la`.`legder_group_id`)))
LEFT JOIN `users` `u` ON (((`u`.`id` = `la`.`user_id`)
AND (`la`.`type` = 2))))
LEFT JOIN `locations` `l` ON (((`l`.`id` = `la`.`location_id`)
AND (`la`.`type` = 3))))