Exemplo n.º 1
0
 public function addStockMasterTemp($array)
 {
     // App_Controller_Functions::pr($array);
     $to_warehouse_id = $array['hdn_receive_warehouse_id'];
     $from_warehouse_id = $this->_identity->getWarehouseId();
     $transaction_date = App_Controller_Functions::dateToDbFormat($array['transaction_date']);
     $str_qry = "SELECT stock_master.pk_id\n                            FROM\n                            stock_master\n                            where\n                            stock_master.to_warehouse_id='{$to_warehouse_id}'\n                            and stock_master.from_warehouse_id = '{$from_warehouse_id}'\n                            and stock_master.draft=1 and stock_master.transaction_type_id = 2   AND DATE_FORMAT(\n                                stock_master.transaction_date,\n                                '%Y-%m-%d'\n                        ) = '{$transaction_date}' ";
     $this->_em = Zend_Registry::get('doctrine');
     $row = $this->_em->getConnection()->prepare($str_qry);
     $row->execute();
     $result = $row->fetchAll();
     $stock_master_id = $result[0]['pk_id'];
     $detail = $this->_em->getRepository("StockDetail")->findBy(array("stockMaster" => $stock_master_id));
     if (count($detail) > 0) {
         $master = $detail[0]->getStockMaster();
         foreach ($detail as $row) {
             $this->_em->remove($row);
         }
         $this->_em->remove($master);
         $this->_em->flush();
     }
     $stock_master = new StockMaster();
     $type = $array['transaction_type_id'];
     $time_arr = explode(' ', $array['transaction_date']);
     $time = date('H:i:s', strtotime($time_arr[1] . $time_arr[2]));
     $stock_master->setTransactionDate(new \DateTime(App_Controller_Functions::dateToDbFormat($time_arr[0]) . '' . $time));
     $tran_type = $this->_em->getRepository('TransactionTypes')->find($type);
     $stock_master->setTransactionType($tran_type);
     $stock_master->setTransactionReference($array['transaction_reference']);
     $created_by = $this->_em->getRepository('Users')->find($this->_user_id);
     $stock_master->setCreatedBy($created_by);
     $stock_master->setModifiedBy($created_by);
     $stock_master->setParentId(0);
     $stock_master->setCreatedDate(App_Tools_Time::now());
     $stock_master->setModifiedDate(App_Tools_Time::now());
     $activity_id = $this->_em->getRepository('StakeholderActivities')->find($array['hdn_activity_id']);
     $stock_master->setStakeholderActivity($activity_id);
     if (!empty($array['campaign_id'])) {
         $stock_master->setCampaignId($array['campaign_id']);
     }
     if (!empty($array['dispatch_by'])) {
         $stock_master->setDispatchBy($array['dispatch_by']);
     }
     //$trans = $this->getTransactionNumber($type, $array['transaction_date']);
     if ($type == 1) {
         $from_warehouse_id = $this->_em->getRepository('Warehouses')->find($array['from_warehouse_id']);
         $stock_master->setFromWarehouse($from_warehouse_id);
         $to_warehouse_id = $this->_em->getRepository('Warehouses')->find($this->_identity->getWarehouseId());
         $stock_master->setToWarehouse($to_warehouse_id);
     } else {
         if ($type == 2) {
             $from_warehouse_id = $this->_em->getRepository('Warehouses')->find($this->_identity->getWarehouseId());
             $stock_master->setFromWarehouse($from_warehouse_id);
             $to_warehouse_id = $this->_em->getRepository('Warehouses')->find($array['hdn_receive_warehouse_id']);
             $stock_master->setToWarehouse($to_warehouse_id);
         }
     }
     $stock_master->setComments($array['comments']);
     $stock_master->setTransactionNumber('TEMP');
     $stock_master->setDraft(1);
     $this->_em->persist($stock_master);
     $this->_em->flush();
     $id = $stock_master->getPkId();
     //echo $id;
     //exit;
     return $id;
 }
 public function setCampaignId($campaignId)
 {
     $this->__load();
     return parent::setCampaignId($campaignId);
 }
Exemplo n.º 3
0
 public function addStockMasterTemp($array)
 {
     //  App_Controller_Functions::pr($array);
     $to_warehouse_id = $array['hdn_receive_warehouse_id'];
     $from_warehouse_id = $this->_identity->getWarehouseId();
     $str_qry_del = "DELETE stock_detail.*,stock_master.*\n                            FROM\n                            stock_detail,stock_master\n                            where\n                            stock_master.pk_id = stock_detail.stock_master_id\n                            and stock_master.to_warehouse_id='{$to_warehouse_id}'\n                            and stock_master.from_warehouse_id = '{$from_warehouse_id}'\n                            and stock_master.draft=1 and stock_master.transaction_type_id = 2";
     $this->_em = Zend_Registry::get('doctrine');
     $row = $row = $this->_em->getConnection()->prepare($str_qry_del);
     $row->execute();
     if (!empty($array['hdn_stock_master_id'])) {
         $hdn_stock_master_id = $array['hdn_stock_master_id'];
         $str_qry_del = "DELETE stock_detail.*\n                            FROM\n                            stock_detail,stock_master\n                            where\n                            stock_master.pk_id = stock_detail.stock_master_id\n                            and stock_master.pk_id='{$hdn_stock_master_id}' ";
         $this->_em = Zend_Registry::get('doctrine');
         $row = $row = $this->_em->getConnection()->prepare($str_qry_del);
         $row->execute();
         $stock_master = $this->_em->getRepository("StockMaster")->find($array['hdn_stock_master_id']);
     } else {
         $stock_master = new StockMaster();
     }
     $type = $array['transaction_type_id'];
     $time_arr = explode(' ', $array['transaction_date']);
     $time = date('H:i:s', strtotime($time_arr[1] . $time_arr[2]));
     $stock_master->setTransactionDate(new \DateTime(App_Controller_Functions::dateToDbFormat($time_arr[0]) . '' . $time));
     $tran_type = $this->_em->getRepository('TransactionTypes')->find($type);
     $stock_master->setTransactionType($tran_type);
     $stock_master->setTransactionReference($array['transaction_reference']);
     $created_by = $this->_em->getRepository('Users')->find($this->_user_id);
     $stock_master->setCreatedBy($created_by);
     $stock_master->setParentId(0);
     $stock_master->setCreatedDate(new \DateTime(date("Y-m-d")));
     $activity_id = $this->_em->getRepository('StakeholderActivities')->find($array['hdn_activity_id']);
     $stock_master->setStakeholderActivity($activity_id);
     if (!empty($array['campaign_id'])) {
         $stock_master->setCampaignId($array['campaign_id']);
     }
     if (!empty($array['dispatch_by'])) {
         $stock_master->setDispatchBy($array['dispatch_by']);
     }
     //$trans = $this->getTransactionNumber($type, $array['transaction_date']);
     if ($type == 1) {
         $from_warehouse_id = $this->_em->getRepository('Warehouses')->find($array['from_warehouse_id']);
         $stock_master->setFromWarehouse($from_warehouse_id);
         $to_warehouse_id = $this->_em->getRepository('Warehouses')->find($this->_identity->getWarehouseId());
         $stock_master->setToWarehouse($to_warehouse_id);
     } else {
         if ($type == 2) {
             $from_warehouse_id = $this->_em->getRepository('Warehouses')->find($this->_identity->getWarehouseId());
             $stock_master->setFromWarehouse($from_warehouse_id);
             $to_warehouse_id = $this->_em->getRepository('Warehouses')->find($array['hdn_receive_warehouse_id']);
             $stock_master->setToWarehouse($to_warehouse_id);
         }
     }
     $stock_master->setComments($array['comments']);
     $stock_master->setTransactionNumber('TEMP');
     $stock_master->setDraft(1);
     $this->_em->persist($stock_master);
     $this->_em->flush();
     $id = $stock_master->getPkId();
     return $id;
 }