/** * Event function to update the organization data * @param object $evctl */ public function eventEditRecord(EventControler $evctl) { $param_array = (array) $evctl; $id_entity = (int) $evctl->sqrecord; if ($id_entity > 0 && true === $_SESSION["do_crm_action_permission"]->action_permitted('edit', 14, (int) $evctl->sqrecord)) { $obj = $this->getId($id_entity); $obj = (object) $obj; // convert the data array to Object $do_process_plugins = new CRMPluginProcessor(); // process before update plugin. If any error is raised display that. $do_process_plugins->process_action_plugins((int) $evctl->idmodule, $evctl, 3, $id_entity, $obj); if (strlen($do_process_plugins->get_error()) > 2) { $_SESSION["do_crm_messages"]->set_message('error', $do_process_plugins->get_error()); $next_page = NavigationControl::getNavigationLink($evctl->module, "edit"); $dis = new Display($next_page); $dis->addParam("sqrecord", $id_entity); if ($evctl->return_page != '') { $dis->addParam("return_page", $evctl->return_page); } $evctl->setDisplayNext($dis); } else { $do_crm_fields = new CRMFields(); $crm_fields = $do_crm_fields->get_field_information_by_module_as_array((int) $evctl->idmodule); $table_entity = 'sales_order'; $table_entity_custom = 'sales_order_custom_fld'; $table_entity_to_grp = 'sales_order_to_grp_rel'; $table_entity_address = 'sales_order_address'; $entity_data_array = array(); $custom_data_array = array(); $addr_data_array = array(); $assigned_to_as_group = false; foreach ($crm_fields as $crm_fields) { $field_name = $crm_fields["field_name"]; $field_value = $do_crm_fields->convert_field_value_onsave($crm_fields, $evctl, 'edit'); if (is_array($field_value) && count($field_value) > 0) { if ($field_value["field_type"] == 15) { $field_name = 'iduser'; $value = $field_value["value"]; $assigned_to_as_group = $field_value["assigned_to_as_group"]; $group_id = $field_value["group_id"]; } elseif ($field_value["field_type"] == 12) { $value = $field_value["name"]; $avatar_array[] = $field_value; } } else { $value = $field_value; } if ($crm_fields["table_name"] == $table_entity && $crm_fields["idblock"] > 0) { $entity_data_array[$field_name] = $value; } elseif ($crm_fields["table_name"] == $table_entity_custom && $crm_fields["idblock"] > 0) { $custom_data_array[$field_name] = $value; } elseif ($crm_fields["table_name"] == $table_entity_address && $crm_fields["idblock"] > 0) { $addr_data_array[$field_name] = $value; } } $this->update(array($this->primary_key => $id_entity), $table_entity, $entity_data_array); //update quotes other information $upd_array = array("terms_condition" => $evctl->terms_cond, "net_total" => $evctl->net_total_lines, "discount_type" => $evctl->final_discount_type, "discount_value" => $evctl->final_discount_val, "discounted_amount" => $evctl->final_discounted_total, "tax_values" => $evctl->final_tax_val, "taxed_amount" => $evctl->final_tax_amount, "shipping_handling_charge" => $evctl->final_ship_hand_charge, "shipping_handling_tax_values" => $evctl->final_ship_hand_tax_val, "shipping_handling_taxed_amount" => $evctl->final_ship_hand_tax_amount, "final_adjustment_type" => $evctl->final_adjustment, "final_adjustment_amount" => $evctl->final_adjustment_val, "grand_total" => $evctl->grand_total); $this->update(array($this->primary_key => $id_entity), $table_entity, $upd_array); //updating the last_modified,last_modified_by $u_qry = "\n\t\t\t\tupdate `" . $this->getTable() . "` \n\t\t\t\tset \n\t\t\t\t`last_modified` = ? ,\n\t\t\t\t`last_modified_by` = ? \n\t\t\t\twhere `" . $this->primary_key . "` = ?\n\t\t\t\t"; $this->query($u_qry, array(date("Y-m-d H:i:s"), $_SESSION["do_user"]->iduser, $id_entity)); if (count($custom_data_array) > 0) { $this->update(array($this->primary_key => $id_entity), $table_entity_custom, $custom_data_array); } if (count($addr_data_array) > 0) { $this->update(array($this->primary_key => $id_entity), $table_entity_address, $addr_data_array); } if ($assigned_to_as_group === false) { $qry_grp_rel = "DELETE from `{$table_entity_to_grp}` where `idsales_order` = ? LIMIT 1"; $this->query($qry_grp_rel, array($id_entity)); } else { $qry_grp_rel = "select * from `{$table_entity_to_grp}` where `idsales_order` = ?"; $this->query($qry_grp_rel, array($id_entity)); if ($this->getNumRows() > 0) { $this->next(); $id_grp_rel = $this->idsales_order_to_grp_rel; $u_qry = "\n\t\t\t\t\t\tupdate `{$table_entity_to_grp}` \n\t\t\t\t\t\tset \n\t\t\t\t\t\t`idgroup` = ?\n\t\t\t\t\t\twhere `idsales_order_to_grp_rel` = ? LIMIT 1\n\t\t\t\t\t\t"; $this->query($u_qry, array($group_id, $id_grp_rel)); } else { $this->insert($table_entity_to_grp, array("idsales_order" => $id_entity, "idgroup" => $group_id)); } } // Record the history $do_data_history = new DataHistory(); $do_data_history->add_history($id_entity, (int) $evctl->idmodule, 'edit'); $do_data_history->add_history_value_changes($id_entity, (int) $evctl->idmodule, $obj, $evctl); //record the feed $feed_other_assigne = array(); if ($assigned_to_as_group === true) { $feed_other_assigne = array("related" => "group", "data" => array("key" => "newgroup", "val" => $group_id)); } $do_feed_queue = new LiveFeedQueue(); $do_feed_queue->add_feed_queue($id_entity, (int) $evctl->idmodule, $evctl->product_name, 'edit', $feed_other_assigne); $do_line_items = new Lineitems(); $param_array = (array) $evctl; $do_line_items->edit_line_items((int) $evctl->idmodule, $id_entity, $param_array["params"]); // process after update plugin $do_process_plugins->process_action_plugins((int) $evctl->idmodule, $evctl, 4, $id_entity, $obj); $_SESSION["do_crm_messages"]->set_message('success', _('Data updated successfully !')); $next_page = NavigationControl::getNavigationLink($evctl->module, "detail"); $dis = new Display($next_page); $dis->addParam("sqrecord", $id_entity); $evctl->setDisplayNext($dis); } } else { $_SESSION["do_crm_messages"]->set_message('error', _('You do not have permission to edit the record ! ')); $next_page = NavigationControl::getNavigationLink($evctl->module, "list"); $dis = new Display($next_page); $evctl->setDisplayNext($dis); } }
<?php // Copyright SQCRM. For licensing, reuse, modification and distribution see license.txt /** * SalesOrder edit * @author Abhik Chakraborty */ $do_crmfields = new CRMFields(); $do_block = new Block(); $do_block->get_block_by_module($module_id); $do_global_settings = new CRMGlobalSettings(); $inv_terms_cond = $do_global_settings->get_inventory_terms_condition(); $tems_condition = $inv_terms_cond["salesorder_terms_condition"]; $module_obj = new SalesOrder(); $module_obj->getId($sqcrm_record_id); $do_lineitems = new Lineitems(); $do_lineitems->get_line_items($module_id, $sqcrm_record_id); $do_products = new Products(); $lineitems = array(); if ($do_lineitems->getNumRows() > 0) { while ($do_lineitems->next()) { $product_available_tax = ''; if ($do_lineitems->item_type == 'product') { $product_available_tax = $do_products->get_products_tax($do_lineitems->item_value); } $lineitems[] = array("idlineitems" => $do_lineitems->idlineitems, "item_type" => $do_lineitems->item_type, "item_name" => $do_lineitems->item_name, "item_value" => $do_lineitems->item_value, "item_description" => $do_lineitems->item_description, "item_quantity" => $do_lineitems->item_quantity, "item_price" => $do_lineitems->item_price, "discount_type" => $do_lineitems->discount_type, "discount_value" => $do_lineitems->discount_value, "discounted_amount" => $do_lineitems->discounted_amount, "tax_values" => $do_lineitems->tax_values, "product_available_tax" => $product_available_tax, "taxed_amount" => $do_lineitems->taxed_amount, "total_after_discount" => $do_lineitems->total_after_discount, "total_after_tax" => $do_lineitems->total_after_tax, "net_total" => $do_lineitems->net_total); } } //print_r($lineitems); if (isset($_GET["return_page"]) && $_GET["return_page"] != '') { $return = $_GET["return_page"];
/** * function to generate inventory (quote,invoice,sales order,purchase order) PDF * @param integer $idquotes * @param boolean $save * @see http://www.mpdf1.com/mpdf/index.php */ public function generate_inventory_pdf($idrecord, $idmodule, $save = false) { include_once BASE_PATH . THIRD_PARTY_LIB_PATH . "/mpdf/mpdf.php"; //echo BASE_PATH.THIRD_PARTY_LIB_PATH ;exit; $pdf = new \mPDF(); $crm_global_settings = new \CRMGlobalSettings(); if ($idmodule == 13) { $obj = new \Quotes(); $obj->getId($idrecord); $prefix = $crm_global_settings->get_setting_data_by_name('quote_num_prefix'); $inventory_type = _('QUOTE'); $inv = 'q'; $inv_number_fld = 'quote_number'; $inv_date_fld = 'valid_till'; $file_name = 'Quote_' . $prefix . $obj->quote_number . '.pdf'; $inventory_number = _('Quote #'); } elseif ($idmodule == 14) { $obj = new \SalesOrder(); $obj->getId($idrecord); $prefix = $crm_global_settings->get_setting_data_by_name('salesorder_num_prefix'); $inventory_type = _('SALES ORDER'); $inv = 'so'; $inv_number_fld = 'sales_order_number'; $inv_date_fld = 'due_date'; $file_name = 'SalesOrder_' . $prefix . $obj->sales_order_number . '.pdf'; $inventory_number = _('Sales Order #'); } elseif ($idmodule == 15) { $obj = new \Invoice(); $obj->getId($idrecord); $prefix = $crm_global_settings->get_setting_data_by_name('invoice_num_prefix'); $inventory_type = _('INVOICE'); $inv = 'inv'; $inv_number_fld = 'invoice_number'; $inv_date_fld = 'due_date'; $file_name = 'Invoice_' . $prefix . $obj->invoice_number . '.pdf'; $inventory_number = _('Invoice #'); } elseif ($idmodule == 16) { $obj = new \PurchaseOrder(); $obj->getId($idrecord); $prefix = $crm_global_settings->get_setting_data_by_name('purchaseorder_num_prefix'); $inventory_type = _('PURCHASE ORDER'); $inv = 'po'; $inv_number_fld = 'po_number'; $inv_date_fld = 'due_date'; $file_name = 'PurchaseOrder_' . $prefix . $obj->po_number . '.pdf'; $inventory_number = _('Purchase Order #'); } $inventory_logo = $crm_global_settings->get_setting_data_by_name('inventory_logo'); $company_address = $crm_global_settings->get_setting_data_by_name('company_address'); $do_lineitems = new \Lineitems(); $do_lineitems->get_line_items($idmodule, $idrecord); $lineitems = array(); if ($do_lineitems->getNumRows() > 0) { while ($do_lineitems->next()) { $lineitems[] = array("idlineitems" => $do_lineitems->idlineitems, "item_type" => $do_lineitems->item_type, "item_name" => $do_lineitems->item_name, "item_value" => $do_lineitems->item_value, "item_description" => $do_lineitems->item_description, "item_quantity" => $do_lineitems->item_quantity, "item_price" => $do_lineitems->item_price, "discount_type" => $do_lineitems->discount_type, "discount_value" => $do_lineitems->discount_value, "discounted_amount" => $do_lineitems->discounted_amount, "tax_values" => $do_lineitems->tax_values, "taxed_amount" => $do_lineitems->taxed_amount, "total_after_discount" => $do_lineitems->total_after_discount, "total_after_tax" => $do_lineitems->total_after_tax, "net_total" => $do_lineitems->net_total); } } $html = ''; if (is_array($lineitems) && count($lineitems) > 0) { //--load the stylesheet $stylesheet = file_get_contents(BASE_PATH . '/themes/custom-css/inventory_export.css'); $pdf->WriteHTML($stylesheet, 1); $html .= ' <div> <div class="inv_wrapper"> <h1 class="inv_heading">' . $inventory_type . '</h1> <div class="inv_address_wrapper"> <p class="inv_address_section"> <span class="inv_address_to_from">FROM:</span><br> ' . nl2br($company_address) . ' </p> </div> <div class="inv_company_address_wrapper"> <img class="inv_company_address_logo" src="' . $GLOBALS['FILE_UPLOAD_DISPLAY_PATH'] . '/' . $inventory_logo . '"> </div> </div> <div style="clear:both;"></div> <div class="inv_wrapper"> <div class="inv_address_wrapper"> <p class="inv_address_section"> <span class="inv_address_to_from">To:</span><br>' . $this->generate_to_address($obj, $inv) . ' </p> </div> <div class="inv_brief_section"> <table class="inv_brief_section_table"> <tr> <th class="inv_brief_section_table_heading"> <span>' . $inventory_number . '</span> </th> <td class="inv_brief_section_table_content"> <span>' . $prefix . $obj->{$inv_number_fld} . '</span> </td> </tr> <tr> <th class="inv_brief_section_table_heading"> <span>Date</span> </th> <td class="inv_brief_section_table_content"> <span>' . \FieldType9::display_value($obj->{$inv_date_fld}) . '</span> </td> </tr> <tr> <th class="inv_brief_section_table_heading"> <span>Amount Due</span> </th> <td class="inv_brief_section_table_content"> <span>' . \FieldType30::display_value($obj->grand_total) . '</span> </td> </tr> </table> </div> </div> <div style="clear:both;"></div> <br> '; $html .= ' <table class="inv_line_table"> <thead> <tr> <th class="inv_line_table_header inv_line_table_header_width_30"> <span>Item Name</span> </th> <th class="inv_line_table_header inv_line_table_header_width_10"> <span>Qty</span> </th> <th class="inv_line_table_header inv_line_table_header_width_30"> <span>Price</span> </th> <th class="inv_line_table_header inv_line_table_header_width_15"> <span>Total</span> </th> <th class="inv_line_table_header inv_line_table_header_width_15"> <span>Net Price</span> </th> </tr> </thead> '; $html .= '<tbody>'; foreach ($lineitems as $key => $items) { $line_discount = ''; if ($items["discount_type"] == 'direct') { $line_discount = _('Discount') . '-' . \FieldType30::display_value($items["discount_value"]); } elseif ($items["discount_type"] == 'percentage') { $line_discount = _('Discount') . '-' . $items["discount_value"] . ' %'; } else { $line_discount = _('Discount') . '-' . _('no discount'); } $line_tax = ''; if ($items["tax_values"] != '') { $line_tax = ' - ' . rtrim($items["tax_values"], ','); } else { $line_tax = ' - no tax'; } $html .= ' <tr> <td class="inv_line_table_content inv_line_table_content_vertical_top"> <div class="inv_line_table_content_block"> ' . $items["item_name"] . ' <br><br> ' . nl2br($items["item_description"]) . ' </div> </td> <td class="inv_line_table_content inv_line_table_content_vertical_top"> <div class="inv_line_table_content_block"> ' . \FieldType16::display_value($items["item_quantity"]) . ' </div> </td> <td class="inv_line_table_content"> <div class="inv_line_table_content_block"> ' . \FieldType30::display_value($items["item_price"]) . ' </div> <div class="inv_line_table_content_block"> ' . $line_discount . ' </div> <div class="inv_line_table_content_block"> <b>Total after discount</b> </div> <div class="inv_line_table_content_block"> <b>Tax </b> ' . $line_tax . ' </div> </td> <td class="inv_line_table_content"> <div class="inv_line_table_content_block"> ' . \FieldType30::display_value($items["item_price"] * $items["item_quantity"]) . ' </div> <div class="inv_line_table_content_block"> ' . \FieldType30::display_value($items["discounted_amount"]) . ' </div> <div class="inv_line_table_content_block"> ' . \FieldType30::display_value($items["total_after_discount"]) . ' </div> <div class="inv_line_table_content_block"> ' . \FieldType30::display_value($items["taxed_amount"]) . ' </div> </td> <td class="inv_line_table_content inv_line_table_content_vertical_top"> ' . \FieldType30::display_value($items["net_total"]) . ' </td> </tr>'; } $html .= ' </tbody></table>'; $net_discount = ''; if ($obj->discount_type == 'percentage') { $net_discount = $obj->discount_value . ' %'; } elseif ($obj->discount_type == 'direct') { $net_discount = FieldType30::display_value($obj->discount_value); } else { $net_discount = _('no discount'); } $net_tax = ''; if ($obj->tax_values != '') { $net_tax = rtrim($obj->tax_values, ','); } $ship_hand_tax = ''; if ($obj->shipping_handling_tax_values != '') { $ship_hand_tax = rtrim($obj->shipping_handling_tax_values, ','); } $final_adj = ''; if ($obj->final_adjustment_type == 'add') { $final_adj = '(+)'; } elseif ($obj->final_adjustment_type == 'deduct') { $final_adj = '(-)'; } $html .= ' <div style="clear:both;"></div> <br> <div class="inv_grand_total_section"> <table class="inv_grand_total_table"> <tr> <td class="inv_grand_total_table_header"> <span><b>Net Total</b></span> </td> <td class="inv_grand_total_table_content"> <span>' . \FieldType30::display_value($obj->net_total) . '</span> </td> </tr> <tr> <td class="inv_grand_total_table_header"> <span><b>Discount -</b> ' . $net_discount . '</span> </td> <td class="inv_grand_total_table_content"> <span>' . \FieldType30::display_value($obj->discounted_amount) . '</span> </td> </tr> <tr> <td class="inv_grand_total_table_header"> <span><b>Tax -</b> ' . $net_tax . ' </span> </td> <td class="inv_grand_total_table_content"> <span>' . \FieldType30::display_value($obj->taxed_amount) . '</span> </td> </tr> <tr> <td class="inv_grand_total_table_header"> <span><b>Shipping/Handling charges</b></span> </td> <td class="inv_grand_total_table_content"> <span>' . \FieldType30::display_value($obj->shipping_handling_charge) . '</span> </td> </tr> <tr> <td class="inv_grand_total_table_header"> <span><b>Shipping/Handling Tax -</b>' . $ship_hand_tax . '</span> </td> <td class="inv_grand_total_table_content"> <span>' . \FieldType30::display_value($obj->shipping_handling_taxed_amount) . '</span> </td> </tr> <tr> <td class="inv_grand_total_table_header"> <span><b>Final Adjustment</b>' . $final_adj . '</span> </td> <td class="inv_grand_total_table_content"> <span>' . \FieldType30::display_value($obj->final_adjustment_amount) . '</span> </td> </tr> <tr> <td class="inv_grand_total_table_header"> <span><b>Grand Total</span> </td> <td class="inv_grand_total_table_content"> <span>' . \FieldType30::display_value($obj->grand_total) . '</span> </td> </tr> </table> </div> <div style="clear:both;"></div> <br> <h3 class="inv_terms_cond_section"> <span>Terms & Condition</span> </h3> <div style="top:2px;"> <p> ' . nl2br($obj->terms_condition) . ' </p> </div></div>'; } if (true === $save) { $pdf->WriteHTML($html); $pdf->Output(OUTBOUND_PATH . '/' . $file_name, 'F'); return $file_name; } else { $pdf->WriteHTML($html, 2); $pdf->Output($file_name, 'D'); exit; } }