function save_module($module) { global $adb; //in ajax save we should not call this function, because this will delete all the existing product values if ($_REQUEST['action'] != 'PurchaseOrderAjax' && $_REQUEST['ajxaction'] != 'DETAILVIEW' && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates') { //Based on the total Number of rows we will save the product relationship with this entity saveInventoryProductDetails($this, 'PurchaseOrder', $this->update_prod_stock); if (vtlib_isModuleActive("InventoryDetails")) { InventoryDetails::createInventoryDetails($this, 'PurchaseOrder'); } } //In Ajax edit, if the status changed to Received Shipment then we have to update the product stock if ($_REQUEST['action'] == 'PurchaseOrderAjax' && $this->update_prod_stock == 'true') { $inventory_res = $this->db->pquery("select productid, quantity from vtiger_inventoryproductrel where id=?", array($this->id)); $noofproducts = $this->db->num_rows($inventory_res); //We have to update the stock for all the products in this PO for ($prod_count = 0; $prod_count < $noofproducts; $prod_count++) { $productid = $this->db->query_result($inventory_res, $prod_count, 'productid'); $quantity = $this->db->query_result($inventory_res, $prod_count, 'quantity'); $this->db->println("Stock is going to be updated for the productid - {$productid} with quantity - {$quantity}"); addToProductStock($productid, $quantity); } } // Update the currency id and the conversion rate for the purchase order $update_query = "update vtiger_purchaseorder set currency_id=?, conversion_rate=? where purchaseorderid=?"; $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); $adb->pquery($update_query, $update_params); }
function save_module() { global $adb; //in ajax save we should not call this function, because this will delete all the existing product values if ($_REQUEST['action'] != 'QuotesAjax' && $_REQUEST['ajxaction'] != 'DETAILVIEW' && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates') { //Based on the total Number of rows we will save the product relationship with this entity saveInventoryProductDetails($this, 'Quotes'); if (vtlib_isModuleActive("InventoryDetails")) { InventoryDetails::createInventoryDetails($this, 'Quotes'); } } // Update the currency id and the conversion rate for the quotes $update_query = "update vtiger_quotes set currency_id=?, conversion_rate=? where quoteid=?"; $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); $adb->pquery($update_query, $update_params); }
function save_module($module) { global $adb; if ($this->HasDirectImageField) { $this->insertIntoAttachment($this->id, $module); } //in ajax save we should not call this function, because this will delete all the existing product values if (inventoryCanSaveProductLines($_REQUEST)) { //Based on the total Number of rows we will save the product relationship with this entity saveInventoryProductDetails($this, 'PurchaseOrder'); if (vtlib_isModuleActive("InventoryDetails")) { InventoryDetails::createInventoryDetails($this, 'PurchaseOrder'); } } // Update the currency id and the conversion rate for the purchase order $update_query = "update vtiger_purchaseorder set currency_id=?, conversion_rate=? where purchaseorderid=?"; $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); $adb->pquery($update_query, $update_params); }
function save_module($module) { global $updateInventoryProductRel_deduct_stock; if ($this->HasDirectImageField) { $this->insertIntoAttachment($this->id, $module); } $updateInventoryProductRel_deduct_stock = true; //in ajax save we should not call this function, because this will delete all the existing product values if (inventoryCanSaveProductLines($_REQUEST, 'Issuecards')) { //Based on the total Number of rows we will save the product relationship with this entity saveInventoryProductDetails($this, 'Issuecards'); if (vtlib_isModuleActive("InventoryDetails")) { InventoryDetails::createInventoryDetails($this, 'Issuecards'); } } else { if ($_REQUEST['action'] == 'IssuecardsAjax' || $_REQUEST['action'] == 'MassEditSave') { $updateInventoryProductRel_deduct_stock = false; } } // Update the currency id and the conversion rate for the invoice $update_query = "update vtiger_issuecards set currency_id=?, conversion_rate=? where issuecardid=?"; $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); $this->db->pquery($update_query, $update_params); }
function createInventoryDetails($related_focus, $module) { require_once 'modules/InventoryDetails/InventoryDetails.php'; global $adb, $log, $current_user, $currentModule; $save_currentModule = $currentModule; $currentModule = 'InventoryDetails'; $related_to = $related_focus->id; //var_dump($related_focus->column_fields);exit; $taxtype = getInventoryTaxType($module, $related_to); if ($taxtype == 'group') { $query = "SELECT id as related_to , productid , sequence_no ,lineitem_id,quantity , listprice , comment as description , \n\t\t\tquantity * listprice AS extgross, \n\t\t\tCOALESCE( discount_percent, COALESCE( discount_amount *100 / ( quantity * listprice ) , 0 ) ) AS discount_percent, \n\t\t\tCOALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ) ) AS discount_amount, \n\t\t\t(quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 )) AS extnet, \n\t\t\t((quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ))) AS linetotal \n\t\t\tFROM vtiger_inventoryproductrel \n\t\t\tWHERE id = ?"; } elseif ($taxtype == 'individual') { $query = "SELECT id as related_to , productid , sequence_no ,lineitem_id,quantity , listprice , comment as description , \n\t\t\tcoalesce( tax1 , 0 ) AS tax1, coalesce( tax2 , 0 ) AS tax2, coalesce( tax3 , 0 ) AS tax3, \n\t\t\t( COALESCE( tax1, 0 ) + COALESCE( tax2, 0 ) + COALESCE( tax3, 0 ) ) as tax_percent, \n\t\t\tquantity * listprice AS extgross, \n\t\t\tCOALESCE( discount_percent, COALESCE( discount_amount *100 / ( quantity * listprice ) , 0 ) ) AS discount_percent, \n\t\t\tCOALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ) ) AS discount_amount, \n\t\t\t(quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 )) AS extnet, \n\t\t\t((quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ))) * ( COALESCE( tax1, 0 ) + COALESCE( tax2, 0 ) + COALESCE( tax3, 0 ) ) /100 AS linetax, \n\t\t\t((quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ))) * ( 1 + ( COALESCE( tax1, 0 ) + COALESCE( tax2, 0 ) + COALESCE( tax3, 0 )) /100) AS linetotal \n\t\t\tFROM vtiger_inventoryproductrel \n\t\t\tWHERE id = ?"; } $res_inv_lines = $adb->pquery($query, array($related_to)); $accountid = '0'; $contactid = '0'; switch ($module) { case 'Quotes': $accountid = $related_focus->column_fields['account_id']; $contactid = $related_focus->column_fields['contact_id']; break; case 'SalesOrder': $accountid = $related_focus->column_fields['account_id']; $contactid = $related_focus->column_fields['contact_id']; break; case 'Invoice': $accountid = $related_focus->column_fields['account_id']; $contactid = $related_focus->column_fields['contact_id']; break; case 'PurchaseOrder': $contactid = $related_focus->column_fields['contact_id']; break; default: break; } // Delete all InventoryDetails where related with $related_to $res_to_del = $adb->pquery("SELECT inventorydetailsid FROM vtiger_inventorydetails \n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_inventorydetails.inventorydetailsid \n\t\t\t\t\t\t\t\t\tWHERE deleted = 0 AND related_to = ?", array($related_to)); while ($invdrow = $adb->getNextRow($res_to_del, false)) { $invdet_focus = new InventoryDetails(); $invdet_focus->id = $invdrow['inventorydetailsid']; $invdet_focus->trash('InventoryDetails', $invdet_focus->id); } // read $res_inv_lines result to create a new InventoryDetail for each register. // Remember to take the Vendor if the Product is related with this. while ($row = $adb->getNextRow($res_inv_lines, false)) { $invdet_focus = array(); $invdet_focus = new InventoryDetails(); $invdet_focus->id = ''; $invdet_focus->mode = ''; foreach ($invdet_focus->column_fields as $fieldname => $val) { $invdet_focus->column_fields[$fieldname] = $row[$fieldname]; } $_REQUEST['assigntype'] == 'U'; $invdet_focus->column_fields['assigned_user_id'] = $current_user->id; $invdet_focus->column_fields['account_id'] = $accountid; $invdet_focus->column_fields['contact_id'] = $contactid; //Search if the product is related with a Vendor. $vendorid = '0'; $result = $adb->pquery("SELECT vendor_id FROM vtiger_products WHERE productid = ?", array($row['productid'])); if ($adb->num_rows($result) > 0) { $vendorid = $adb->query_result($result, 0, 0); } $invdet_focus->column_fields['vendor_id'] = $vendorid; if ($taxtype == 'group') { $invdet_focus->column_fields['tax_percent'] = 0; $invdet_focus->column_fields['linetax'] = 0; } $invdet_focus->save("InventoryDetails"); } $currentModule = $save_currentModule; }
function save_module($module) { global $updateInventoryProductRel_deduct_stock; if ($this->HasDirectImageField) { $this->insertIntoAttachment($this->id, $module); } $updateInventoryProductRel_deduct_stock = true; //Checking if quote_id is present and updating the quote status if ($this->column_fields['quote_id'] != '') { $newStatus = GlobalVariable::getVariable('QuoteStatusOnSalesOrderSave', 'Accepted'); if ($newStatus != 'DoNotChange') { $qt_id = $this->column_fields['quote_id']; $query1 = 'update vtiger_quotes set quotestage=? where quoteid=?'; $this->db->pquery($query1, array($newStatus, $qt_id)); } } //in ajax save we should not call this function, because this will delete all the existing product values if ($_REQUEST['action'] != 'SalesOrderAjax' && $_REQUEST['ajxaction'] != 'DETAILVIEW' && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates') { //Based on the total Number of rows we will save the product relationship with this entity saveInventoryProductDetails($this, 'SalesOrder'); if (vtlib_isModuleActive("InventoryDetails")) { InventoryDetails::createInventoryDetails($this, 'SalesOrder'); } } else { if ($_REQUEST['action'] == 'SalesOrderAjax' || $_REQUEST['action'] == 'MassEditSave') { $updateInventoryProductRel_deduct_stock = false; } } // Update the currency id and the conversion rate for the sales order $update_query = "update vtiger_salesorder set currency_id=?, conversion_rate=? where salesorderid=?"; $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); $this->db->pquery($update_query, $update_params); }
function save_module($module) { global $updateInventoryProductRel_deduct_stock; $updateInventoryProductRel_deduct_stock = true; //Checking if salesorderid is present and updating the SO status if (!empty($this->column_fields['salesorder_id'])) { $newStatus = GlobalVariable::getVariable('SalesOrderStatusOnInvoiceSave', 'Approved'); if ($newStatus != 'DoNotChange') { $so_id = $this->column_fields['salesorder_id']; $query1 = 'update vtiger_salesorder set sostatus=? where salesorderid=?'; $this->db->pquery($query1, array($newStatus, $so_id)); } } //in ajax save we should not call this function, because this will delete all the existing product values if (isset($this->_recurring_mode) && $this->_recurring_mode == 'recurringinvoice_from_so' && isset($this->_salesorderid) && $this->_salesorderid != '') { // We are getting called from the RecurringInvoice cron service! $this->createRecurringInvoiceFromSO(); if (vtlib_isModuleActive("InventoryDetails")) { InventoryDetails::createInventoryDetails($this, 'Invoice'); } } else { if (isset($_REQUEST)) { if ($_REQUEST['action'] != 'InvoiceAjax' && $_REQUEST['ajxaction'] != 'DETAILVIEW' && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates') { //Based on the total Number of rows we will save the product relationship with this entity saveInventoryProductDetails($this, 'Invoice'); if (vtlib_isModuleActive("InventoryDetails")) { InventoryDetails::createInventoryDetails($this, 'Invoice'); } } else { if ($_REQUEST['action'] == 'InvoiceAjax' || $_REQUEST['action'] == 'MassEditSave') { $updateInventoryProductRel_deduct_stock = false; } } } } // Update the currency id and the conversion rate for the invoice $update_query = "update vtiger_invoice set currency_id=?, conversion_rate=? where invoiceid=?"; $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); $this->db->pquery($update_query, $update_params); }
public static function createInventoryDetails($related_focus, $module) { global $adb, $log, $current_user, $currentModule; $save_currentModule = $currentModule; $currentModule = 'InventoryDetails'; $related_to = $related_focus->id; $taxtype = getInventoryTaxType($module, $related_to); if ($taxtype == 'group') { $query = "SELECT id as related_to, vtiger_inventoryproductrel.productid, sequence_no, lineitem_id, quantity, listprice, comment as description,\n\t\t\tquantity * listprice AS extgross,\n\t\t\tCOALESCE( discount_percent, COALESCE( discount_amount *100 / ( quantity * listprice ) , 0 ) ) AS discount_percent,\n\t\t\tCOALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ) ) AS discount_amount,\n\t\t\t(quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 )) AS extnet,\n\t\t\t((quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ))) AS linetotal,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.cost_price else vtiger_service.cost_price end as cost_price,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.vendor_id else 0 end as vendor_id\n\t\t\tFROM vtiger_inventoryproductrel\n\t\t\tLEFT JOIN vtiger_products ON vtiger_products.productid=vtiger_inventoryproductrel.productid\n\t\t\tLEFT JOIN vtiger_service ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid\n\t\t\tWHERE id = ?"; } elseif ($taxtype == 'individual') { $query = "SELECT id as related_to, vtiger_inventoryproductrel.productid, sequence_no, lineitem_id, quantity, listprice, comment as description,\n\t\t\tcoalesce( tax1 , 0 ) AS tax1, coalesce( tax2 , 0 ) AS tax2, coalesce( tax3 , 0 ) AS tax3,\n\t\t\t( COALESCE( tax1, 0 ) + COALESCE( tax2, 0 ) + COALESCE( tax3, 0 ) ) as tax_percent,\n\t\t\tquantity * listprice AS extgross,\n\t\t\tCOALESCE( discount_percent, COALESCE( discount_amount *100 / ( quantity * listprice ) , 0 ) ) AS discount_percent,\n\t\t\tCOALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ) ) AS discount_amount,\n\t\t\t(quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 )) AS extnet,\n\t\t\t((quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ))) * ( COALESCE( tax1, 0 ) + COALESCE( tax2, 0 ) + COALESCE( tax3, 0 ) ) /100 AS linetax,\n\t\t\t((quantity * listprice) - COALESCE( discount_amount, COALESCE( discount_percent * quantity * listprice /100, 0 ))) * ( 1 + ( COALESCE( tax1, 0 ) + COALESCE( tax2, 0 ) + COALESCE( tax3, 0 )) /100) AS linetotal,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.cost_price else vtiger_service.cost_price end as cost_price,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.vendor_id else 0 end as vendor_id\n\t\t\tFROM vtiger_inventoryproductrel\n\t\t\tLEFT JOIN vtiger_products ON vtiger_products.productid=vtiger_inventoryproductrel.productid\n\t\t\tLEFT JOIN vtiger_service ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid\n\t\t\tWHERE id = ?"; } $res_inv_lines = $adb->pquery($query, array($related_to)); $accountid = '0'; $contactid = '0'; switch ($module) { case 'Quotes': $accountid = $related_focus->column_fields['account_id']; $contactid = $related_focus->column_fields['contact_id']; break; case 'SalesOrder': $accountid = $related_focus->column_fields['account_id']; $contactid = $related_focus->column_fields['contact_id']; break; case 'Invoice': $accountid = $related_focus->column_fields['account_id']; $contactid = $related_focus->column_fields['contact_id']; break; case 'PurchaseOrder': $contactid = $related_focus->column_fields['contact_id']; break; default: break; } // Delete all InventoryDetails where related with $related_to $res_to_del = $adb->pquery('SELECT inventorydetailsid FROM vtiger_inventorydetails INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_inventorydetails.inventorydetailsid WHERE deleted = 0 AND related_to = ? and lineitem_id not in (select lineitem_id from vtiger_inventoryproductrel where id=?)', array($related_to, $related_to)); while ($invdrow = $adb->getNextRow($res_to_del, false)) { $invdet_focus = new InventoryDetails(); $invdet_focus->id = $invdrow['inventorydetailsid']; $invdet_focus->trash('InventoryDetails', $invdet_focus->id); } $requestindex = 1; while (isset($_REQUEST['deleted' . $requestindex]) and $_REQUEST['deleted' . $requestindex] == 1) { $requestindex++; } // read $res_inv_lines result to create a new InventoryDetail for each register. // Remember to take the Vendor if the Product is related with this. while ($row = $adb->getNextRow($res_inv_lines, false)) { $invdet_focus = array(); $invdet_focus = new InventoryDetails(); $rec_exists = $adb->pquery('SELECT inventorydetailsid FROM vtiger_inventorydetails INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_inventorydetails.inventorydetailsid WHERE deleted = 0 AND lineitem_id = ?', array($row['lineitem_id'])); if ($adb->num_rows($rec_exists) > 0) { $invdet_focus->id = $adb->query_result($rec_exists, 0, 0); $invdet_focus->retrieve_entity_info($invdet_focus->id, 'InventoryDetails'); $invdet_focus->mode = 'edit'; } else { $invdet_focus->id = ''; $invdet_focus->mode = ''; } foreach ($invdet_focus->column_fields as $fieldname => $val) { if (isset($_REQUEST[$fieldname . $requestindex])) { $invdet_focus->column_fields[$fieldname] = vtlib_purify($_REQUEST[$fieldname . $requestindex]); } elseif (isset($row[$fieldname])) { $invdet_focus->column_fields[$fieldname] = $row[$fieldname]; } } $invdet_focus->column_fields['lineitem_id'] = $row['lineitem_id']; $_REQUEST['assigntype'] = 'U'; $invdet_focus->column_fields['assigned_user_id'] = $current_user->id; $invdet_focus->column_fields['account_id'] = $accountid; $invdet_focus->column_fields['contact_id'] = $contactid; if ($taxtype == 'group') { $invdet_focus->column_fields['tax_percent'] = 0; $invdet_focus->column_fields['linetax'] = 0; } $handler = vtws_getModuleHandlerFromName('InventoryDetails', $current_user); $meta = $handler->getMeta(); $invdet_focus->column_fields = DataTransform::sanitizeRetrieveEntityInfo($invdet_focus->column_fields, $meta); $invdet_focus->save("InventoryDetails"); $requestindex++; while (isset($_REQUEST['deleted' . $requestindex]) and $_REQUEST['deleted' . $requestindex] == 1) { $requestindex++; } } $currentModule = $save_currentModule; }
function save_module($module) { //Checking if quote_id is present and updating the quote status if ($this->column_fields["quote_id"] != '') { $qt_id = $this->column_fields["quote_id"]; $query1 = "update vtiger_quotes set quotestage='Accepted' where quoteid=?"; $this->db->pquery($query1, array($qt_id)); } //in ajax save we should not call this function, because this will delete all the existing product values if ($_REQUEST['action'] != 'SalesOrderAjax' && $_REQUEST['ajxaction'] != 'DETAILVIEW' && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates') { //Based on the total Number of rows we will save the product relationship with this entity saveInventoryProductDetails($this, 'SalesOrder'); if (vtlib_isModuleActive("InventoryDetails")) { InventoryDetails::createInventoryDetails($this, 'SalesOrder'); } } // Update the currency id and the conversion rate for the sales order $update_query = "update vtiger_salesorder set currency_id=?, conversion_rate=? where salesorderid=?"; $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id); $this->db->pquery($update_query, $update_params); }