示例#1
0
 public static function Factory(POrder $header, $line_data, &$errors = array())
 {
     if (empty($line_data['order_id'])) {
         $line_data['order_id'] = $header->id;
     }
     if (empty($line_data['line_number'])) {
         $line_data['line_number'] = $header->getNextLineNumber();
     }
     if ($line_data['revised_qty'] > 0 && $line_data['price'] > 0) {
         if (empty($line_data['id'])) {
             // New Line
             $line_data['order_qty'] = $line_data['os_qty'] = $line_data['revised_qty'];
             $line_data['status'] = 'N';
         } else {
             // Amended Line
             if ($line_data['status'] == 'N') {
                 $line_data['os_qty'] = $line_data['revised_qty'];
             } elseif ($line_data['revised_qty'] >= $line_data['del_qty']) {
                 $line_data['os_qty'] = $line_data['revised_qty'] - $line_data['del_qty'];
                 if ($line_data['os_qty'] == 0) {
                     $line_data['status'] = 'R';
                 }
             } else {
                 $errors[] = 'Revised Quantity less than Delivered Quantity';
                 return false;
             }
         }
     } else {
         $errors[] = 'Zero quantity or net value';
         return false;
     }
     $line_data['item_description'] = $line_data['description'];
     if ($line_data['productline_id'] == -1) {
         $line_data['productline_id'] = '';
         $line_data['stitem_id'] = '';
     } elseif (!empty($line_data['productline_id'])) {
         $productline = DataObjectFactory::Factory('POProductline');
         $productline->load($line_data['productline_id']);
         if ($productline->isLoaded()) {
             $productlineheader = $productline->product_detail;
             if (is_null($productlineheader->stitem_id)) {
                 $line_data['item_description'] = $productline->getDescription();
                 $line_data['stitem_id'] = '';
             } else {
                 $line_data['item_description'] = $productlineheader->stitem;
                 $line_data['stitem_id'] = $productlineheader->stitem_id;
             }
             if (empty($line_data['price'])) {
                 $line_data['price'] = $productline->getPrice('', '', $productline->slmaster_id);
             }
             if (empty($line_data['glaccount_id'])) {
                 $line_data['glaccount_id'] = $productline->glaccount_id;
             }
             if (empty($line_data['glcentre_id'])) {
                 $line_data['glcentre_id'] = $productline->glcentre_id;
             }
             if (empty($line_data['stuom_id'])) {
                 $line_data['stuom_id'] = $productlineheader->stuom_id;
             }
             if (empty($line_data['tax_rate_id'])) {
                 $line_data['tax_rate_id'] = $productlineheader->tax_rate_id;
             }
         }
         // Check if glaccount_centre_id exists - can be any value including null
         if (!array_key_exists('glaccount_centre_id', $line_data)) {
             $line_data['glaccount_centre_id'] = GLAccountCentre::getAccountCentreId($line_data['glaccount_id'], $line_data['glcentre_id'], $errors);
         }
         if (empty($line_data['net_value'])) {
             $line_data['net_value'] = bcmul($line_data['price'], $line_data['revised_qty']);
         }
     }
     if (empty($line_data['description'])) {
         $line_data['description'] = $line_data['item_description'];
     }
     $line_data['line_discount'] = 0;
     $line_data['currency_id'] = $header->currency_id;
     $line_data['rate'] = $header->rate;
     $line_data['twin_currency_id'] = $header->twin_currency_id;
     $line_data['twin_rate'] = $header->twin_rate;
     $line_data['base_net_value'] = round(bcdiv($line_data['net_value'], $line_data['rate'], 4), 2);
     $line_data['twin_net_value'] = round(bcmul($line_data['base_net_value'], $line_data['twin_rate'], 4), 2);
     if (empty($line_data['due_delivery_date'])) {
         $line_data['due_delivery_date'] = un_fix_date($header->due_date);
     }
     return parent::Factory($line_data, $errors, 'POrderLine');
 }
示例#2
0
文件: POrder.php 项目: uzerpllp/uzerp
 public function save_model($data)
 {
     // Used to save Order Header and Order Lines from import or copy of existing
     $flash = Flash::Instance();
     if (empty($data['POrder']) || empty($data['POrderLine'])) {
         $flash->addError('Error trying to import order');
         return false;
     }
     $errors = array();
     $db = DB::Instance();
     $db->StartTrans();
     $header = $data['POrder'];
     $lines_data = DataObjectCollection::joinArray($data['POrderLine'], 0);
     if (!$lines_data || empty($lines_data)) {
         $lines_data[] = $data['POrderLine'];
     }
     $order = POrder::Factory($header, $errors);
     if (!$order || count($errors) > 0) {
         $errors[] = 'Order validation failed';
     } elseif (!$order->save()) {
         $errors[] = 'Order creation failed';
     }
     foreach ($lines_data as $line) {
         $line['order_id'] = $order->{$order->idField};
         $orderline = POrderLine::Factory($order, $line, $errors);
         if (!$orderline || count($errors) > 0) {
             $errors[] = 'Order Line validation failed for line ' . $line['line_number'];
         } elseif (!$orderline->save()) {
             $errors[] = 'Order Line creation failed for line ' . $line['line_number'];
         }
     }
     if (count($errors) === 0) {
         if (!$order->save()) {
             $errors[] = 'Error updating Purchase Order totals';
         } else {
             $result = array('internal_id' => $order->{$order->idField}, 'internal_identifier_field' => $order->identifierField, 'internal_identifier_value' => $order->getidentifierValue());
         }
     }
     if (count($errors) > 0) {
         $flash->addErrors($errors);
         $db->FailTrans();
         $result = false;
     }
     $db->CompleteTrans();
     return $result;
 }
示例#3
0
 public function getMaterialsTotals()
 {
     // do not have project_id on SO
     // probably need new table to link project/task to PO/SO
     $orders = new POrder();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('project_id', '=', $this->id));
     $totals['Materials']['total_costs'] = $orders->getSumFields(array('net_value'), $cc);
     $orders = new SOrder();
     $cc = new ConstraintChain();
     $cc->add(new Constraint('project_id', '=', $this->id));
     $totals['Materials']['total_charges'] = $orders->getSumFields(array('net_value'), $cc);
     return $totals;
 }
示例#4
0
 public function deactivateAction()
 {
     $this->view->disable();
     if ($this->request->isAjax()) {
         $order_id = $this->request->get('order_id');
         $status = 1;
         $order = POrder::findFirst($order_id);
         $order->deactivated = 1;
         if (!$order->save()) {
             $status = 0;
         }
         echo $status;
     }
 }