- if ($delivery_line->standard_cost != 0) {
-
- /*first the cost of sales entry*/
- // 2008-08-01. If there is a Customer Dimension, then override with this,
- // else take the Item Dimension (if any)
- $dim = ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]);
- $dim2 = ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]);
-
- add_gl_trans_std_cost(13, $delivery_no,
- $delivery->document_date, $stock_gl_code["cogs_account"], $dim, $dim2, "",
- $delivery_line->standard_cost * $delivery_line->qty_dispatched,
- payment_person_types::customer(), $delivery->customer_id,
- "The cost of sales GL posting could not be inserted");
-
- /*now the stock entry*/
- //$stock_gl_code = get_stock_gl_code($order_line->stock_id);
-
- add_gl_trans_std_cost(13, $delivery_no, $delivery->document_date,
- $stock_gl_code["inventory_account"], 0, 0, "",
- (-$delivery_line->standard_cost * $delivery_line->qty_dispatched),
- payment_person_types::customer(), $delivery->customer_id,
- "The stock side of the cost of sales GL posting could not be inserted");
+
+ if (is_inventory_item($delivery_line->stock_id)) {
+ // Fixed Assets
+ if ($delivery->fixed_asset) {
+ $fa_purchase_cost = get_purchase_cost($delivery_line->stock_id);
+ $fa_depreciation = $fa_purchase_cost - $delivery_line->standard_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,
+ "The cost of sales GL posting could not be inserted");
+ /*then remove asset*/
+ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date,
+ $stock_gl_code["inventory_account"], $dim, $dim2, "",
+ -$fa_purchase_cost,
+ PT_CUSTOMER, $delivery->customer_id,
+ "The stock side of the cost of sales GL posting could not be inserted");
+ /*finally adjust sales account with the remaining*/
+ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date,
+ $stock_gl_code["cogs_account"], $dim, $dim2, "",
+ ($fa_purchase_cost - $fa_depreciation),
+ PT_CUSTOMER, $delivery->customer_id,
+ "The stock side of the cost of sales GL posting could not be inserted");
+ }
+ // Invetory Items
+ else if ($delivery_line->standard_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, "",
+ $delivery_line->standard_cost * $delivery_line->qty_dispatched,
+ PT_CUSTOMER, $delivery->customer_id,
+ "The cost of sales GL posting could not be inserted");
+
+ /*now the stock entry*/
+ add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date,
+ $stock_gl_code["inventory_account"], $dim, $dim2, "",
+ (-$delivery_line->standard_cost * $delivery_line->qty_dispatched),
+ PT_CUSTOMER, $delivery->customer_id,
+ "The stock side of the cost of sales GL posting could not be inserted");
+ }