/magehelp/application/controllers/procurement.php
PHP | 2916 lines | 2106 code | 420 blank | 390 comment | 350 complexity | 307cea1c9ee6777683149faca5454931 MD5 | raw file
Possible License(s): LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- require_once ("secure_area.php");
- class Procurement extends Secure_area
- {
- private $user;
- private $username;
-
- function __construct()
- {
- parent::__construct('procurement');
- $this->user= $this->User->get_logged_in_employee_info();
- $this->username = $this->user->last_name." ".$this->user->first_name;
- $param = array('user' => $this->user->username);
- $this->load->library('acl-library/Acl',$param,'Acl');
-
- }
- //moved to parent class
- // function assignEntityToUser(){
- // $ids = $_REQUEST['ids'];
- // $entity = $_REQUEST['entity'];
- // $role = $_REQUEST['role'];
- // $user_id = $_REQUEST['user_id'];
- // if ($entity=='rfq'){
- // $model = 'Request_quote_master';
- // }
- // else if ($entity=='quote'){
- // $model = 'Purchase_quote_master';
- // }
- // else if ($entity=='order'){
- // $model = 'Purchase_order_master';
- // }
- // else if ($entity=='receipt_item'){
- // $model = 'Receipt_item';
- // }
- // else if ($entity=='receipt'){
- // $model = 'Receipt_master';
- // }
- // else if ($entity=='invoice'){
- // $model = 'Purchase_invoice_master';
- // }
- // if (!empty($ids) && !empty($role) ){
- // if (empty($user_id)){
- // $user_id = $this->user->person_id;
- // }
- // if ($role =='approver'){
- // $upd_data['approved_by'] = $user_id;
- // }
- // else if ($role =='receiver'){
- // $upd_data['received_by'] = $user_id;
- // $upd_data['owner_id'] = $user_id;
- // }
- // else if ($role =='payer'){
- // $upd_data['payer_id'] = $user_id;
- // $upd_data['owner_id'] = $user_id;
- // }
- // else if ($role =='owner'){
- // $upd_data['owner_id'] = $user_id;
- // }
- // foreach($ids as $id){
- //
- // $this->$model->update(array('id'=>$id),$upd_data);
- // }
- // }
- // }
- // function prepareAssignDialog(){
- //// var_dump(($this->User->getAllEligibleOwners('rfq')));
- //// var_dump(($this->User->getAllEligibleApprovers('rfq')));
- // $entity = $_REQUEST['entity'];
- // if ($entity=='order'){
- // $owners = $this->User->getAllEligibleReceivers($_REQUEST['entity']);
- // }
- // else{
- // $owners = $this->User->getAllEligibleOwners($_REQUEST['entity']);
- // }
- //
- //
- // $approvers = $this->User->getAllEligibleApprovers($_REQUEST['entity']);
- // $adminUserOptions =null;
- // $userOptions = null;
- // foreach($owners as $owner) {
- //
- // $name=$owner["username"];
- // $id=$owner["person_id"];
- // if (!empty($name)){
- // $userOptions.="<OPTION VALUE=\"$id\">".$name;
- // }
- // }
- // foreach($approvers as $approver) {
- //
- // $name=$approver["username"];
- // $id=$approver["person_id"];
- // if (!empty($name)){
- // $adminUserOptions.="<OPTION VALUE=\"$id\">".$name;
- // }
- // }
- // $data['userOptions'] = $userOptions;
- // $data['adminUserOptions'] = $adminUserOptions;
- // echo json_encode($data);
- // }
- /* PURCHASE QUOTE GRID START */
-
- function index()
- {
- $users = $this->User->getAllUsersByRole(null,array('field_name'=>'role_name',array('Everyone','Guest')));
-
- foreach($users as $user) {
- $user_id=$user["person_id"];
- $username=$user["username"];
- //$value = $denom["denom_json"];
- if (!empty($user_id)){
- $userOptions.="<OPTION VALUE=\"$user_id\">".$username;
- }
- }
- $data['userOptions'] = $userOptions;
- $this->load->view("procurement/quote/purchase_quote_grid",$data);
- }
-
-
- /* common functions */
- function populateSuppliers(){
- echo populateSuppliers();
- }
-
- function getCostPrice(){
- $id = $_REQUEST['productid'];
- $productDetails = $this->Product_price->getByProductId($id);
- echo $productDetails->cost_price;
- }
-
- function getPriceFromPricelist(){
- $product_id = $_REQUEST['product_id'];
- $pricelist_id = $_REQUEST['pricelist_id'];
- $supplier_id = $_REQUEST['supplier_id'];
- $results = $this->Supplier_rate_items->getPriceForProduct($product_id,$pricelist_id,$supplier_id);
- echo $results[0]['base_price'] ;
- }
-
- /* end common */
-
- /*start quote */
-
- function populateRFQ(){
- $quotedata=array();
- $status = $_REQUEST['_status'];
-
- $where = array();
- $in_where = array();
- setOwnerStatusCommon($where,$in_where);
-
- $griddata= populateGridCommon('Request_quote_master',$where,null,$in_where);
- $dbrows = $griddata['db_data'];
- $data = $griddata['grid_metadata'];
- foreach ($dbrows as $dp){
- if ($status==self::WAITING_FOR_APPROVAL){
- /* we dont need actions column in approval grid . So not passing the blank */
- array_push($quotedata, array('id'=> $dp['id'],'dprow' => array($dp['reference'],$dp['supplier_name'],$dp['estimated_value'],$dp['owner_id'],$dp['status'],$dp['raised_by_name'],$dp['owner_name'],$dp['needed_by_date'],$dp['approved_by_name'],$dp['supplier_id'],$dp['warehouse_id'],$dp['approved_by'])));
- }
- //remove
- // else if ($status==self::REJECTED){
- // /* Add Extra Columns Rejected and Rejected Notes Remove Status */
- // array_push($quotedata, array('id'=> $dp['id'],'dprow' => array($dp['reference'],$dp['supplier_name'],$dp['estimated_value'],$dp['raised_by_name'],$dp['owner_name'],$dp['needed_by_date'],$dp['approved_by_name'],$dp['approval_notes'])));
- // }
- // //remove
- // else if ($status==self::OPEN){
- // array_push($quotedata, array('id'=> $dp['id'],'dprow' => array('',$dp['reference'],$dp['supplier_name'],$dp['estimated_value'],$dp['status'],$dp['raised_by_name'],$dp['owner_name'],$dp['needed_by_date'])));
- // }
- else if (is_array($status)){
- array_push($quotedata, array('id'=> $dp['id'],'dprow' => array($dp['reference'],$dp['supplier_name'],$dp['estimated_value'],$dp['owner_id'],$dp['status'],$dp['raised_by_name'],$dp['owner_name'],$dp['needed_by_date'],$dp['approved_by_name'],$dp['supplier_id'],$dp['warehouse_id'])));
- }
- else {
- array_push($quotedata, array('id'=> $dp['id'],'dprow' => array($dp['reference'],$dp['supplier_name'],$dp['estimated_value'],$dp['status'],$dp['raised_by_name'],$dp['owner_name'],$dp['needed_by_date'],$dp['notes'],$dp['approved_by_name'],$dp['approval_notes'])));
- }
- }
- $data['quotedata'] = $quotedata;
- echo json_encode($data);
- }
- function createRFQ(){
- $id = $_REQUEST['quoteId'];
- $purchase_quote_data['supplier_id'] = $_REQUEST['supplierId'];
- $purchase_quote_data['warehouse_id'] = $_REQUEST['warehouseId'];
- $dateObj = DateTime::createFromFormat('d/m/Y', $_REQUEST['reqdate']);
- log_message('debug','converted '.$dateObj->format('Y-m-d'));
- $purchase_quote_data['needed_by_date'] = $dateObj->format('Y-m-d');
- $comments = appendComments($_REQUEST['notes'], 'notes');
- $purchase_quote_data['owner_id'] = $this->user->person_id;
-
- if (empty($id)){
- $purchase_quote_data['raised_by'] = $this->user->person_id;
- $id = $this->Request_quote_master->createRequest($purchase_quote_data,array('notes'=>$comments));
- }
- else {
- $where_clause = array('id'=>$id);
- $this->Request_quote_master->update($where_clause, $purchase_quote_data,array('notes'=>$comments));
- }
- echo $id;
- }
- //this function validates the record after close button of dialog being pressed. If no items are aadded the record is deleted
- function closeValidate(){
- $id = $_REQUEST['id'];
- $entity = $_REQUEST['entity'];
- $items_count = $_REQUEST['items_count'];
- if ($entity=='quote'){
- $model = 'Purchase_quote_master';
- $itemModel= 'Purchase_quote_item';
- $where_clause_quote_item = array('quote_id'=>$id);
- }
- else if ($entity=='rfq'){
- $model = 'Request_quote_master';
- $itemModel= 'Request_quote_item';
- $where_clause_quote_item = array('rfq_id'=>$id);
- }
-
- if (!empty($id)){
-
- if ($items_count>0){
- $where_clause_quote = array('id'=>$id);
- $this->$model->update($where_clause_quote,array('status'=>self::OPEN));
- $this->$itemModel->update($where_clause_quote_item,array('status'=>self::OPEN));
- }
- }
- }
-
- function modifyRFQ (){
- $id = $_REQUEST['id'];
-
- $oper = $_REQUEST['oper'];
- $this->db->trans_start();
- if ($oper=='edit'){
- if (!empty($_REQUEST['needed_date'])){
- $dateObj = DateTime::createFromFormat('d/m/Y', $_REQUEST['needed_date']);
- log_message('debug','converted item date '.$dateObj->format('Y-m-d'));
- $purchase_quote_data['needed_by_date'] = $dateObj->format('Y-m-d');
- }
-
- if (!empty($_REQUEST['warehouse_id'])){
- $purchase_quote_data['warehouse_id'] = $_REQUEST['warehouse_id'];
- }
- $comments = appendComments($_REQUEST['notes'], 'notes');
- //while editing the supplier id is passed.
- $purchase_quote_data['supplier_id'] = $_REQUEST['supplier_name'];
- $where_clause_quote = array('id'=>$id);
-
- $this->Request_quote_master->update($where_clause_quote,$purchase_quote_data,array('notes'=>$comments));
-
- }
- else if ($oper=='del'){
- $idAraay = $_REQUEST['id'];
- foreach($idAraay as $tempId){
- $where_clause_quote = array('id'=>$tempId);
- $this->Request_quote_master->update($where_clause_quote,array('status'=>'cancelled'));
- $where_clause_quote_item = array('rfq_id'=>$tempId);
- $this->Request_quote_item->update($where_clause_quote_item,array('status'=>'cancelled'));
- }
-
- }
- $this->db->trans_complete();
- }
-
- function addRFQItemBulk (){
- //$id = $_REQUEST['quoteId'];
- $data= $_REQUEST['data'];
- $purchase_quote_data['rfq_id'] = $_REQUEST['rfq'];
- $this->db->trans_start();
- foreach($data as $itemDetails){
- $purchase_quote_data['product_id'] = $itemDetails['id'];
- $purchase_quote_data['requested_quantity'] = $itemDetails['quantity'];
- $this->createRFQItem($purchase_quote_data);
- }
- $this->db->trans_complete();
- }
-
- function addRFQItem (){
- //$id = $_REQUEST['quoteId'];
- $product_id = $_REQUEST['productid'];
- $purchase_quote_data['rfq_id'] = $_REQUEST['rfq'];
- $purchase_quote_data['product_id'] = $product_id;
- $needed_by = $_REQUEST['needeedByDate'];
- if (!empty($needed_by)){
- $dateObj = DateTime::createFromFormat('d/m/Y', $needed_by);
- log_message('debug','converted item date '.$dateObj->format('Y-m-d'));
- $purchase_quote_data['needed_by_date'] = $dateObj->format('Y-m-d');
- }
- $purchase_quote_data['requested_quantity'] = $_REQUEST['quantity'];
- $purchase_quote_data['expected_price'] = $_REQUEST['exprice'];
- $purchase_quote_data['estimated_value'] = $_REQUEST['quantity']*$_REQUEST['exprice'];
- $purchase_quote_data['comments'] = $_REQUEST['descItem'];
- $id = $this->createRFQItem($purchase_quote_data);
- }
- //business logic
- function createRFQItem($purchase_quote_data){
- $this->db->trans_start();
- /* insert into quote item */
-
- $this->Request_quote_item->insert($purchase_quote_data);
- log_message('debug','insert statement ='.$this->db->last_query());
- $id = $this->db->insert_id();
- /* end insert */
-
- /* update reference number in quote item */
- $where_clause = array('id'=>$id);
- $this->Request_quote_item->update($where_clause, array('reference' => 10000000 + $id));
- /* end update */
-
- /* update estimated value in quote master */
- $rfq_id = $purchase_quote_data['rfq_id'];
- $quote_details=$this->Request_quote_master->getById($rfq_id);
- $estimated_value = $quote_details->estimated_value + $purchase_quote_data['estimated_value'];
- $upd_data['estimated_value'] = $estimated_value;
- if ($quote_details->status==self::DRAFT){
- //if the status is draft that means previously there was no items and for the first time we are adding items.
- // so we set the status as open
- $upd_data['status'] = self::OPEN;
- }
- $this->Request_quote_master->update(array('id'=>$rfq_id),$upd_data);
- log_message('debug','update statement ='.$this->db->last_query());
- /* end update estimated value in quote master */
-
- $this->db->trans_complete();
- return $id;
- }
- function modifyRFQItem (){
- $id = $_REQUEST['line_id'];
- $item_details=$this->Request_quote_item->getById($id);
- $rfq_id = $item_details->rfq_id;
- $current_est_value = $item_details->estimated_value;
- $oper = $_REQUEST['oper'];
- $this->db->trans_start();
- if ($oper=='edit'){
- if (!empty($_REQUEST['needed_by_date'])){
- $dateObj = DateTime::createFromFormat('d/m/Y', $_REQUEST['needed_by_date']);
- log_message('debug','converted item date '.$dateObj->format('Y-m-d'));
- $purchase_quote_data['needed_by_date'] = $dateObj->format('Y-m-d');
- }
- $purchase_quote_data['requested_quantity'] = $_REQUEST['quantity'];
- $purchase_quote_data['expected_price'] = $_REQUEST['expected_price'];
- $comments = appendComments($_REQUEST['comments'], 'comments');
- $purchase_quote_data['estimated_value'] = $_REQUEST['requested_quantity']*$_REQUEST['expected_price'];
- $where_clause = array('id'=>$id);
-
- $this->Request_quote_item->update($where_clause,$purchase_quote_data,array('comments'=>$comments));
-
- $quote_details=$this->Request_quote_master->getById($rfq_id);
- $estimated_value = $quote_details->estimated_value - $current_est_value + $purchase_quote_data['estimated_value'];
- $this->Request_quote_master->update(array('id'=>$rfq_id),array('estimated_value'=>$estimated_value));
- }
- else if ($oper=='del'){
- $quote_details=$this->Request_quote_master->getById($rfq_id);
- $estimated_value = $quote_details->estimated_value - $item_details->estimated_value;
- $this->Request_quote_master->update(array('id'=>$rfq_id),array('estimated_value'=>$estimated_value));
- $where_clause = array('id'=>$id);
- $this->Request_quote_item->update($where_clause,array('status'=>'cancelled'));
-
- }
- $this->db->trans_complete();
-
- }
-
- function populateRFQItems(){
- $quoteid = $_REQUEST['quoteId'];
- if (!empty($quoteid)){
- $quotedata = array();
- $where = array('rfq_id' => $quoteid );
- $griddata= populateGridCommon('Request_quote_item',$where);
- $dbrows = $griddata['db_data'];
- $data = $griddata['grid_metadata'];
- foreach ($dbrows as $dbrow){
- array_push($quotedata, array('id'=> $dbrow['id'],'dprow' => array($dbrow['name'],$dbrow['requested_quantity'],$dbrow['needed_by_date'],$dbrow['expected_price'],$dbrow['estimated_value'],$dbrow['comments'])));
- }
- $data['quoteitemdata'] = $quotedata;
- echo json_encode($data);
- }
-
- }
-
- function generateQuoteFromRFQ(){
- $ids= $_REQUEST['ids'];
-
- foreach($ids as $id){
-
- log_message('debug',' id '.$id);
- $rfq_details=$this->Request_quote_master->getById($id,null,true);
- if ($rfq_details['status']==self::OPEN) {
- $this->db->trans_start();
- //$this->Request_quote_master->update(array('id'=>$id),array('approved_by'=>$this->user->person_id));
- $this->generateQuoteInternal($rfq_details);
- $this->db->trans_complete();
- }
-
- }
-
- }
-
- function getCommentsForEntity(){
- $entity = $_REQUEST['entity'];
- $id = $_REQUEST['id'];
-
- if ($entity == 'rfq'){
- $model = 'Request_quote_master';
- $col_array = array('notes','approval_notes');
- }
- else if ($entity == 'quote'){
- $model = 'Purchase_quote_master';
- $col_array = array('notes','approval_notes');
- }
- else if ($entity == 'order'){
- $model = 'Purchase_order_master';
- $col_array = array('receiving_notes');
-
- }
- else if ($entity == 'receipt_item'){
- $model = 'Receipt_item';
- $col_array = array('receiving_notes','pp_approval_notes');
-
- }
-
- if (!empty($id)){
-
-
- $details=$this->$model->getById($id,$col_array,true);
- echo json_encode($details);
- }
-
- }
- function addCommentsForEntity(){
- $entity = $_REQUEST['entity'];
- $id = $_REQUEST['id'];
- $note_type = $_REQUEST['note_type'];
- // if ($entity == 'rfq'){
- // $model = 'Request_quote_master';
- // $col_array = array('notes','approval_notes');
- // }
- // else if ($entity == 'quote'){
- // $model = 'Purchase_quote_master';
- // $col_array = array('notes','approval_notes');
- // }
- // else if ($entity == 'order'){
- // $model = 'Purchase_order_master';
- // $col_array = array('receiving_notes');
- //
- // }
- if ($entity == 'receipt_item'){
- $model = 'Receipt_item';
- if ($note_type=='pp_approval'){
- $comments = appendComments($_REQUEST['notes'], 'pp_approval_notes');
- }
-
- }
-
- if (!empty($id)){
-
- $this->$model->update($id,null,array('pp_approval_notes'=>$comments));
- }
-
- }
-
- function generatePOFromQuote(){
- $ids= $_REQUEST['ids'];
-
- foreach($ids as $id){
-
- log_message('debug',' id '.$id);
- $quote_details=$this->Purchase_quote_master->getById($id,null,true);
- if ($quote_details['status']==self::OPEN ||$quote_details['status']==self::WAITING_FOR_APPROVAL ) {
- $this->db->trans_start();
- $this->Purchase_quote_master->update(array('id'=>$id),array('approved_by'=>$this->user->person_id));
- $this->generatePOInternal($quote_details);
- $this->db->trans_complete();
- }
-
- }
-
- }
-
- /* PURCHASE QUOTE GRID END*/
-
- /* APPROVAL GRUD START */
-
- function approveOrReject(){
- $id= $_REQUEST['quoteId'];
- $action= $_REQUEST['action'];
- $entity= $_REQUEST['entity'];
- if ($entity=='quote'){
- $model = 'Purchase_quote_master';
- $itemModel= 'Purchase_quote_item';
- $parent_id = 'quote_id';
-
- }
- else if ($entity=='rfq'){
- $model = 'Request_quote_master';
- $itemModel= 'Request_quote_item';
- $parent_id = 'rfq_id';
-
- }
- log_message('debug',' id '.$id);
- log_message('debug',' action '.$action);
- $quote_details=$this->$model->getById($id,null,true);
- if ($quote_details['status']==self::WAITING_FOR_APPROVAL ) {
- if ($action == 'approve'){
- $this->db->trans_start();
-
- if ($entity=='quote'){
- $this->$model->update(array('id'=>$id),array('approved_by'=>$this->user->person_id,'approval_notes'=>$_REQUEST['quote_approval_notes']));
- $this->generatePOInternal($quote_details);
- }
- else if ($entity=='rfq'){
- $this->$model->update(array('id'=>$id),array('approved_by'=>$this->user->person_id,'approval_notes'=>$_REQUEST['quote_approval_notes'],'status'=>self::SUBMITTEDTOQUOTE));
- $this->generateQuoteInternal($quote_details);
- }
- $this->db->trans_complete();
- }
- else if ($action == 'reject'){
- $this->db->trans_start();
- $this->$model->update(array('id'=>$id),array('status'=>self::REJECTED,'approved_by'=>$this->user->person_id,'approval_notes'=>$_REQUEST['quote_approval_notes']));
- $item_details=$this->$itemModel->getByQuoteId($id);
- foreach ($item_details as $item_data){
- $this->$itemModel->update(array('id'=>$item_data['id']),array('status'=>self::REJECTED));
- }
- $this->db->trans_complete();
- }
-
- }
-
- }
- function approveQuotesInBulk(){
- $ids= $_REQUEST['ids'];
- // $this->db->trans_start();
- foreach($ids as $id){
- $quote_details=$this->Request_quote_master->getById($id,null,true);
- if ($quote_details['status']==self::OPEN ||$quote_details['status']==self::WAITING_FOR_APPROVAL ) {
- $this->db->trans_start();
- $this->Request_quote_master->update(array('id'=>$id),array('approved_by'=>$this->user->person_id,'status'=>self::SUBMITTEDTOQUOTE));
- $this->generateQuoteInternal($quote_details);
- $this->db->trans_complete();
- }
- }
- //$this->db->trans_complete();
-
- }
-
- /* APPROVAL GRID END */
-
- /* REJECTED GRID START*/
- function reopen (){
- $ids= $_REQUEST['ids'];
- $entity= $_REQUEST['entity'];
- if ($entity=='quote'){
- $model = 'Purchase_quote_master';
- $itemModel= 'Purchase_quote_item';
- $parent_id = 'quote_id';
-
- }
- else if ($entity=='rfq'){
- $model = 'Request_quote_master';
- $itemModel= 'Request_quote_item';
- $parent_id = 'rfq_id';
-
- }
-
- foreach($ids as $id){
-
- log_message('debug',' id '.$id);
- $quote_details=$this->$model->getById($id,null,true);
- if ($quote_details['status']==self::REJECTED ) {
- $this->db->trans_start();
- $this->$model->update(array('id'=>$id),array('status'=>self::OPEN,'last_updated_by'=>$this->user->person_id));
- $item_details=$this->$itemModel->getByQuoteId($id);
- foreach ($item_details as $item_data){
-
- $this->$itemModel->update(array('id'=>$item_data['id']),array('status'=>self::OPEN));
-
- }
- $this->db->trans_complete();
- }
-
- }
- }
- /* REJECTED GRID END*/
-
- /* COMMON FUNCTIONS FOR RFQ GRIDS */
- private function generatePOInternal($quote_details){
-
- $id=$quote_details['id'];
- $order_data['owner_id'] = $quote_details['owner_id'];
- $order_data['needed_by_date'] = $quote_details['needed_by_date'];
- $order_data['generated_by'] = $this->user->person_id;
- $order_data['quote_id'] = $quote_details['id'];
- log_message('debug',json_encode($order_data));
- $order_id = $this->createOrder($order_data);
- log_message('debug',$this->db->last_query());
- $this->Purchase_quote_master->update(array('id'=>$id),array('status'=>self::ORDERED,'order_id'=>$order_id));
- log_message('debug',$this->db->last_query());
- //now update line item status
- $item_details=$this->Purchase_quote_item->getByQuoteId($id);
- foreach ($item_details as $item_data){
- if ($item_data['status'] == self::OPEN || $item_data['status'] == self::WAITING_FOR_APPROVAL){
- $order_item_data['name'] = $item_data['name'];
- $order_item_data['sku'] = $item_data['sku'];
- $order_item_data['product_id'] = $item_data['product_id'];
- $order_item_data['estimated_value'] = $item_data['estimated_value'];
- $order_item_data['needed_by_date'] = $item_data['needed_by_date'];
- $order_item_data['quoted_quantity'] = $item_data['quoted_quantity'];
- //repeatative ..as of now as no difference between quoted and ordered quantity
- $order_item_data['ordered_quantity'] = $item_data['quoted_quantity'];
- $order_item_data['expected_price'] = $item_data['expected_price'];
- $order_item_data['order_id'] =$order_id;
- $order_item_data['quote_line_id'] = $item_data['id'];
- $order_line_id = $this->createOrderItem($order_item_data);
- $this->Purchase_quote_item->update(array('id'=>$item_data['id']),array('status'=>self::ORDERED,'order_line_id'=>$order_line_id));
- }
- }
-
- }
- public function createOrder($purchase_quote_data){
- $this->db->trans_start();
- $this->Purchase_order_master->insert($purchase_quote_data);
- $id = $this->db->insert_id();
- $where_clause = array('id'=>$id);
- $this->Purchase_order_master->update($where_clause, array('reference' => 10000000 + $id));
- $this->db->trans_complete();
- return $id;
- }
-
- /*end quote */
-
- /* RECEIVING GRID START */
-
- function populatePOToReceive(){
- // $person_id = $this->user->person_id;
- //$in_where=array('field_name'=>'status','value_array'=>array(self::OPEN,self::RECEIVING,self::RECEIVED)) ;
- $this->populatePOInternal();
-
- }
-
- /* RECEIVING GRID END */
-
- function populatePayments(){
- $invoiceId = $_REQUEST['invoiceId'];
- $orderId = $_REQUEST['orderId'];
- $type = $_REQUEST['type'];
- if (!empty($invoiceId) || !empty($orderId)){
- $paymentdata = array();
- if (!empty($invoiceId)){
- $where['invoice_id'] = $invoiceId;
- }
- if (!empty($orderId)){
- $where['order_id'] = $orderId;
- }
- if (!empty($type)){
- $where['payment_type'] = $type;
- }
-
- $griddata= populateGridCommon('Outgoing_payment',$where);
- $dbrows = $griddata['db_data'];
- $data = $griddata['grid_metadata'];
- foreach ($dbrows as $dbrow){
- $isAdvance = 'No';
- if ($dbrow['parent_id'] != 0){
- // we have advance payment
- $isAdvance = 'Yes';
- }
- array_push($paymentdata, array('id'=> $dbrow['id'],'dprow' => array($dbrow['payment_reference'],$dbrow['payment_mode'],$dbrow['payment_type'],$dbrow['amount'],$dbrow['comments'],$isAdvance,$dbrow['parent_id'])));
- }
- $data['paymentdata'] = $paymentdata;
- echo json_encode($data);
- }
- }
-
-
- function populateReceipts(){
- $where = array();
- $in_where = array();
- $status = $_REQUEST['_status'];
- //default status
- if (empty($status)){
- //$where['invoice_id'] = $invoice_id;
- $in_where=array('field_name'=>'status','value_array'=>array(self::READYTOINVOICEMEMO)) ;
-
- }
- setOwnerStatusCommon($where,$in_where);
-
-
- $page = $_REQUEST['page'];
- $limit = $_REQUEST['rows'];
- $sidx = $_REQUEST['sidx'];
- $sord = $_REQUEST['sord'];
- $searchOn = $_REQUEST['_search'];
-
- if (!empty($person_id)){
- $where['owner_id'] = $person_id;
- }
-
- //standard response parameters
- $quotedata = array();
- $count = $this->Receipt_master->totalNoOfRows($where,null,null,$in_where);
- if( $count > 0 && $limit > 0) {
- $total_pages = ceil($count/$limit);
- } else {
- $total_pages = 0;
- }
- if ($page > $total_pages) $page=$total_pages;
- $start = $limit*$page - $limit;
-
- // if for some reasons start position is negative set it to 0
- // typical case is that the user type 0 for the requested page
- if($start <0) $start = 0;
- $clauses = array('orderBy'=>$sidx,'orderDir'=>$sord,'startLimit'=>$start,'limit'=>$limit);
-
- $data['total'] = $total_pages;
- $data['page'] = $page;
- $data['records'] = $count;
- if($searchOn=='true') {
-
- $filters = json_decode($_REQUEST['filters'],true);
- $groupOp = $filters['groupOp'];
- $rules = $filters['rules'];
- $like_condition = array();
- foreach ($rules as $rule){
- $field = $rule['field'];
- $op= $rule['op'];
- $input = $rule['data'];
- if ($field == 'order_reference' ){
- $orderDetails = $this->Purchase_order_master->getGridByReference($input);
- $like_condition['order_id'] = $orderDetails['id'];
- }
- else if ($field == 'quote_reference'){
- $orderDetails = $this->Purchase_order_master->getGridByQuoteReference($input);
- $like_condition['order_id'] = $orderDetails['id'];
- }
- else if ($field == 'supplier_name'){
- $supplierDetails = $this->Supplier->getByName($input);
- $like_condition['supplier_id'] = $supplierDetails['id'];
- }
- else {
- $like_condition[$field] = trim($input);
- }
-
- }
- $quotes = $this->Receipt_master->getAll(false,$where,null,$clauses,$like_condition,$in_where);
- }
- else {
- $quotes = $this->Receipt_master->getAll(false,$where,null,null,null,$in_where);
- }
-
- foreach ($quotes as $dp){
- $orderDetails = $this->Purchase_order_master->getGridById($dp['order_id']);
-
- array_push($quotedata, array('id'=> $dp['id'],'dprow' => array($dp['reference'],$dp['supplier_receipt_number'],$orderDetails['supplier_name'],$dp['status'],$dp['order_id'],$orderDetails['reference'],$orderDetails['quote_reference'],$dp['owner_name'],$dp['owner_id'],$dp['approved_by_name'],$dp['approved_by'])));
- }
- $data['quotedata'] = $quotedata;
- echo json_encode($data);
- }
-
-
-
- function populatePOInternal(){
-
- $where = array();
- $in_where = array();
- setOwnerStatusCommon($where,$in_where);
-
-
- //standard response parameters
- $orderdata = array();
- $griddata= populateGridCommon('Purchase_order_master',$where,null,$in_where);
- $dbrows = $griddata['db_data'];
- $data = $griddata['grid_metadata'];
-
- foreach ($dbrows as $dbrow){
- array_push($orderdata, array('id'=> $dbrow['id'],'dprow' => array($dbrow['reference'],$dbrow['quote_reference'],$dbrow['supplier_name'],$dbrow['estimated_value'],$dbrow['owner_id'],$dbrow['status'],$dbrow['raised_by_name'],$dbrow['order_generated_by_name'],$dbrow['owner_name'],$dbrow['needed_by_date'],$dbrow['received_by_name'],$dbrow['approved_by_name'],$dbrow['supplier_id'],$dbrow['warehouse_id'],$dbrow['received_by'])));
- }
- $data['orderdata'] = $orderdata;
- echo json_encode($data);
- }
-
-
- function validateReceiving(){
- $order_id = $_REQUEST['order_id'];
- // this note is for order
- $receiving_notes = $_REQUEST['receiving_notes'];
- //check the no of order line items with status receiving.
- $totalNoOfRowsByOrderIdReceived = $this->Purchase_order_item->totalNoOfRows(array('order_id'=>$order_id,'status'=>self::RECEIVED));
- $totalNoOfRowsByOrderIdTotal = $this->Purchase_order_item->totalNoOfRows(array('order_id'=>$order_id));
- if ($totalNoOfRowsByOrderIdReceived == $totalNoOfRowsByOrderIdTotal){
- // all the order lines are received
-
- $this->Purchase_order_master->update(array('id'=>$order_id,'status'=>self::RECEIVING),array('status'=>self::RECEIVED,'receiving_notes'=>$receiving_notes));
- $this->Receipt_master->update(array('order_id'=>$order_id,'status'=>self::RECEIVING),array('status'=>self::RECEIVED));
- }
- else {
- $this->Purchase_order_master->update(array('id'=>$order_id,'status'=>self::RECEIVING),array('receiving_notes'=>$receiving_notes));
- }
-
- }
-
- function modifyOrder (){
- $id = $_REQUEST['id'];
-
- $oper = $_REQUEST['oper'];
- $this->db->trans_start();
- if ($oper=='edit'){
- //$dateObj = DateTime::createFromFormat('d/m/Y', $_REQUEST['needed_by_date']);
- //log_message('debug','converted item date '.$dateObj->format('Y-m-d'));
- $purchase_quote_data['needed_by_date'] = $_REQUEST['needed_by_date'];
- $purchase_quote_data['supplier_name'] = $_REQUEST['supplier_name'];
- $where_clause_quote = array('id'=>$id);
-
- $this->Purchase_quote_master->update($where_clause_quote,$purchase_quote_data);
-
- }
- else if ($oper=='del'){
- $idAraay = explode(",", $id);
- foreach($idAraay as $tempId){
- $where_clause_quote = array('id'=>$tempId);
- $this->Purchase_quote_master->update($where_clause_quote,array('status'=>'cancelled'));
- $where_clause_quote_item = array('quote_id'=>$tempId);
- $this->Purchase_quote_item->update($where_clause_quote_item,array('status'=>'cancelled'));
- }
-
- }
- $this->db->trans_complete();
- }
-
- function addOrderItem (){
- //$id = $_REQUEST['quoteId'];
- $product_id = $_REQUEST['productid'];
- $purchase_quote_data['quote_id'] = $_REQUEST['orderId'];
- $purchase_quote_data['product_id'] = $product_id;
- $dateObj = DateTime::createFromFormat('d/m/Y', $_REQUEST['needeedByDate']);
- log_message('debug','converted item date '.$dateObj->format('Y-m-d'));
- $purchase_quote_data['needed_by_date'] = $dateObj->format('Y-m-d');
- $purchase_quote_data['quoted_quantity'] = $_REQUEST['quantity'];
- $purchase_quote_data['expected_price'] = $_REQUEST['exprice'];
- $purchase_quote_data['estimated_value'] = $_REQUEST['quantity']*$_REQUEST['exprice'];
- $purchase_quote_data['comments'] = $_REQUEST['descItem'];
- $productDetails = $this->Product->getByProductId($product_id);
- $purchase_quote_data['sku'] = $productDetails->barcode;
- $purchase_quote_data['name'] = $productDetails->product_name;
- $id = $this->createQuoteItem($purchase_quote_data);
- }
- //business logic
- function createOrderItem($purchase_quote_data){
- $this->db->trans_start();
- /* insert into quote item */
-
- $this->Purchase_order_item->insert($purchase_quote_data);
- log_message('debug','insert statement ='.$this->db->last_query());
- $id = $this->db->insert_id();
- /* end insert */
-
- /* update reference number in quote item */
- $where_clause = array('id'=>$id);
- $this->Purchase_order_item->update($where_clause, array('reference' => 10000000 + $id));
- /* end update */
-
- $this->db->trans_complete();
- return $id;
- }
- function modifyOrderItem (){
- $id = $_REQUEST['id'];
- $item_details=$this->Purchase_quote_item->getById($id);
- $quote_id = $item_details->quote_id;
- $current_est_value = $item_details->estimated_value;
- $oper = $_REQUEST['oper'];
- $this->db->trans_start();
- if ($oper=='edit'){
- //$dateObj = DateTime::createFromFormat('d/m/Y', $_REQUEST['needed_by_date']);
- //log_message('debug','converted item date '.$dateObj->format('Y-m-d'));
- $purchase_quote_data['needed_by_date'] = $_REQUEST['needed_by_date'];
- $purchase_quote_data['quoted_quantity'] = $_REQUEST['quoted_quantity'];
- $purchase_quote_data['expected_price'] = $_REQUEST['expected_price'];
- $purchase_quote_data['comments'] = $_REQUEST['comments'];
- $purchase_quote_data['estimated_value'] = $_REQUEST['quoted_quantity']*$_REQUEST['expected_price'];
- $where_clause = array('id'=>$id);
-
- $this->Purchase_quote_item->update($where_clause,$purchase_quote_data);
-
- $quote_details=$this->Purchase_quote_master->getById($quote_id);
- $estimated_value = $quote_details->estimated_value - $current_est_value + $purchase_quote_data['estimated_value'];
- $this->Purchase_quote_master->update(array('id'=>$quote_id),array('estimated_value'=>$estimated_value));
- }
- else if ($oper=='del'){
- $quote_details=$this->Purchase_quote_master->getById($quote_id);
- $estimated_value = $quote_details->estimated_value - $item_details->estimated_value;
- $this->Purchase_quote_master->update(array('id'=>$quote_id),array('estimated_value'=>$estimated_value));
- $where_clause = array('id'=>$id);
-
- $this->Purchase_quote_item->update($where_clause,array('status'=>'cancelled'));
- }
- $this->db->trans_complete();
-
- }
-
- function populateOrderItems(){
- $orderid = $_REQUEST['orderId'];
- if (!empty($orderid)){
- $orderitemdata = array();
- $where = array('order_id' => $orderid );
- $griddata= populateGridCommon('Purchase_order_item',$where);
- $dbrows = $griddata['db_data'];
- $data = $griddata['grid_metadata'];
- foreach ($dbrows as $dbrow){
- array_push($orderitemdata, array('id'=> $dbrow['id'],'dprow' => array($dbrow['product_id'],$dbrow['name'],$dbrow['quoted_quantity'],$dbrow['received_quantity'],$dbrow['returned_quantity'],$dbrow['cnbd_quantity'],$dbrow['pp_quantity'],$dbrow['needed_by_date'],$dbrow['expected_price'],$dbrow['estimated_value'],$dbrow['received_value'],$dbrow['returned_value'],$dbrow['pp_value'],$dbrow['comments'])));
- }
- $data['orderitemdata'] = $orderitemdata;
- echo json_encode($data);
- }
-
- }
-
- function populateReceiptItems(){
- $receiptId = $_REQUEST['receiptId'];
- $orderLineId = $_REQUEST['orderLineId'];
- $receipt_line_value_in =array();
- $populateGrid= true;
- // as of now keep default oper as "receipt"
- $oper = "receipt";
-
- if (!empty($_REQUEST['oper'])){
- $oper = $_REQUEST['oper'];
- }
- $where = array();
- $in_where = array();
- setOwnerStatusCommon($where,$in_where);
- //standard response parameters
- $quotedata = array();
- if ($oper=="receipt"){
-
- $where['receipt_id'] = $receiptId ;
- }
- else if ($oper=="orderline"){
- $where['order_line_id'] = $orderLineId ;
- }
- // else if ($oper=="pp"){
- // $where= array(/*'pp_quantity >' => 0 ,*/'owner_id'=>$this->user->person_id,'status !='=>self::COMPLETE);
- // }
- else if ($oper=="pp_approve"){
- $where['pp_quantity >']= 0;
- $receipt_line_value_array = array_unique($this->Receipt_partpayment->getAll(false,array('status'=>self::WAITING_FOR_APPROVAL),array('receipt_line_id')));
- //dont fir the query if there is no pp item with wfa mode
- if (count($receipt_line_value_array)==0){
- $populateGrid = false;
- }
- foreach ($receipt_line_value_array as $value){
- array_push($receipt_line_value_in,$value['receipt_line_id']);
- }
-
- }
- if ($populateGrid===true){
- $griddata= populateGridCommon('Receipt_item',$where,null,array('field_name'=>'id','value_array'=>$receipt_line_value_in));
- $quotes = $griddata['db_data'];
- $data = $griddata['grid_metadata'];
- foreach ($quotes as $dp){
- $receipt_data = $this->Receipt_master->getById($dp['receipt_id'],array('supplier_receipt_number','reference','owner_id','owner_name'),true);
- $po_item_data = $this->Purchase_order_item->getById($dp['order_line_id'],array('reference','order_id'),true);
- //$test = $po_item_data['reference'];
- array_push($quotedata, array('id'=> $dp['id'],'dprow' => array($dp['reference'],$dp['batch_number']/*receipt line reference*/,$receipt_data['supplier_receipt_number'],$receipt_data['reference'],/*receipt reference*/
- $dp['receipt_id'],$po_item_data['order_id'], $dp['order_line_id'],$po_item_data['reference'],$dp['product_id'],$dp['name'],$dp['expiry_date'],$dp['vat'],$dp['ordered_quantity'],$dp['received_quantity'],$dp['received_value'],$dp['pp_quantity'],$dp['pp_value'],$dp['returned_quantity'],$dp['returned_value'],$dp['pp_status'],/*$dp['receiving_notes'],$dp['returned_notes'],*/$receipt_data['owner_name'],$receipt_data['owner_id'],$dp['approved_by_name'],$dp['approved_by'])));
- }
- }
-
- $data['receiptitemdata'] = $quotedata;
- echo json_encode($data);
-
-
- }
-
- function populatePartpaymentItems(){
- $ppdata = array();
- $receipt_line_id= $_REQUEST['receipt_line_id'];
-
- $where = array('receipt_line_id' => $receipt_line_id );
- $in_where['field_name'] = 'status' ;
- $in_where['value_array'] = $_REQUEST['_status'] ;
-
-
- $griddata= populateGridCommon('Receipt_partpayment',$where,array('id','receipt_id','receipt_line_id',
- 'pp_quantity','pp_value','pp_notes','status'),$in_where);
- $dbrows = $griddata['db_data'];
- $data = $griddata['grid_metadata'];
-
-
- foreach ($dbrows as $row){
- array_push($ppdata, array('id'=> $row['id'],'dprow' => array($row['receipt_id'],$row['receipt_line_id'],
- $row['pp_quantity'], $row['pp_value'],$row['pp_notes'],$row['status'])));
- }
- $data['ppdata'] = $ppdata;
- echo json_encode($data);
-
-
- }
-
- function getOrderDetails(){
- $orderId=$_REQUEST['orderId'];
- if (!empty($orderId)){
- $order = $this->Purchase_order_master->getGridById($orderId);
- echo json_encode($order);
- }
- }
- function getQuoteDetails(){
- $quoteId=$_REQUEST['quoteId'];
- if (!empty($quoteId)){
- $quote = $this->Purchase_quote_master->getGridById($quoteId);
- echo json_encode($quote);
- }
- }
- function getRFQDetails(){
- $quoteId=$_REQUEST['quoteId'];
- if (!empty($quoteId)){
- $quote = $this->Request_quote_master->getGridById($quoteId);
- echo json_encode($quote);
- }
- }
- function loadPOGrid()
- {
-
- $this->load->view("procurement/purchaseorder/purchase_order_grid",$data);
- }
- function loadOpenInvoicesGrid()
- {
-
- $this->load->view("procurement/invoice/purchase_invoice_grid",$data);
- }
- function loadFormFragment(){
- $this->load->view("procurement/purchaseorder/po_details",$data);
- }
- function loadNotesFragment(){
- $this->load->view("procurement/purchaseorder/po_notes",$data);
- }
-
- function loadWaitingForApprovalQuotesGrid (){
- $this->load->view("procurement/quote/approval/quote_approval_grid",$data);
- }
- function loadRejectedQuotesGrid (){
- $this->load->view("procurement/quote/rejected/quote_rejected_grid",$data);
- }
- function loadRejectedRFQGrid (){
- $this->load->view("procurement/quote/rejected/request_rejected_grid",$data);
- }
-
- function loadQuoteFormFragment(){
- $this->load->view("procurement/quote/approval/quote_details",$data);
- }
- function loadQuoteNotesFragment(){
- $this->load->view("procurement/quote/approval/quote_notes",$data);
- }
- function loadWaitingForApprovalRFQGrid (){
- $this->load->view("procurement/quote/approval/request_approval_grid",$data);
- }
- function loadWaitingForApprovalRFQFormFragment(){
- $this->load->view("procurement/quote/approval/request_details",$data);
- }
- function loadWaitingForApprovalRFQNotesFragment(){
- $this->lo…
Large files files are truncated, but you can click here to view the full file