+ if ($line->qty_dispatched != 0) {
+ add_stock_move(ST_CUSTDELIVERY, $line->stock_id, $delivery_no,
+ $delivery->Location, $delivery->document_date, $delivery->reference,
+ -$line->qty_dispatched, $line->unit_cost,
+ $line_price*(1-$line->discount_percent));
+
+ $mb_flag = get_mb_flag($line->stock_id);
+
+ if (is_fixed_asset($mb_flag)) {
+ $sql = "UPDATE ".TB_PREF."stock_master SET inactive=1, material_cost=0
+ WHERE stock_id=".db_escape($line->stock_id);
+ db_query($sql,"The cost details for the fixed asset could not be updated");
+ }
+
+ $stock_gl_code = get_stock_gl_code($line->stock_id);
+
+ // If there is a Customer Dimension, then override with this,
+ // else take the Item Dimension (if any)
+ $dim = ($delivery->dimension_id != $customer['dimension_id'] ? $delivery->dimension_id :
+ ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]));
+ $dim2 = ($delivery->dimension2_id != $customer['dimension2_id'] ? $delivery->dimension2_id :
+ ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]));
+ if ($delivery->is_prepaid())
+ {
+ $sales_account = ($branch_data['sales_account'] != "" ? $branch_data['sales_account'] : $stock_gl_code['sales_account']);
+
+ $total += add_gl_trans_customer(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, $sales_account, $dim, $dim2,
+ -$line_taxfree_price, $delivery->customer_id);
+ }
+ /* insert gl_trans to credit stock and debit cost of sales at standard cost*/
+
+ if (is_inventory_item($line->stock_id)) {
+ // Fixed Assets
+ if ($delivery->fixed_asset) {
+ $fa_purchase_cost = get_purchase_cost($line->stock_id);
+ $fa_depreciation = $fa_purchase_cost - $line->unit_cost;
+ /*first remove depreciation*/
+ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no,
+ $delivery->document_date, $stock_gl_code["adjustment_account"], $dim, $dim2, "",
+ $fa_depreciation,
+ PT_CUSTOMER, $delivery->customer_id);
+ /*then remove asset*/
+ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date,
+ $stock_gl_code["inventory_account"], 0, 0, "",
+ -$fa_purchase_cost,
+ PT_CUSTOMER, $delivery->customer_id);
+ /*finally adjust sales account with the remaining*/
+ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date,
+ $stock_gl_code["cogs_account"], 0, 0, "",
+ ($fa_purchase_cost - $fa_depreciation),
+ PT_CUSTOMER, $delivery->customer_id);
+ }
+ // Invetory Items
+ else if ($line->unit_cost != 0) {
+ /*first the cost of sales entry*/
+ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no,
+ $delivery->document_date, $stock_gl_code["cogs_account"], $dim, $dim2, "",
+ $line->unit_cost * $line->qty_dispatched,
+ PT_CUSTOMER, $delivery->customer_id);
+
+ /*now the stock entry*/
+ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date,
+ $stock_gl_code["inventory_account"], 0, 0, "",
+ (-$line->unit_cost * $line->qty_dispatched),
+ PT_CUSTOMER, $delivery->customer_id);
+ }