Beispiel #1
0
 static function validBinLocation($bin_id, $location_id)
 {
     $whbin = new WHBin();
     $whbin->load($bin_id);
     if (!$whbin || $whbin->whlocation_id != $location_id) {
         return false;
     } else {
         return true;
     }
 }
Beispiel #2
0
 static function prepareMove($data, &$errors)
 {
     $item = DataObjectFactory::Factory('STItem');
     $item->load($data['stitem_id']);
     $copyfields = array('std_cost', 'std_mat', 'std_lab', 'std_osc', 'std_ohd', 'latest_cost', 'latest_mat', 'latest_lab', 'latest_osc', 'latest_ohd');
     $from = array();
     $to = array();
     $from['stitem_id'] = $to['stitem_id'] = $data['stitem_id'];
     // Link the pair of transaction through the transfer_id
     $transferrule = DataObjectFactory::Factory('WHTransferrule');
     $transfer_id = $transferrule->getTransferId();
     $from['transfer_id'] = $to['transfer_id'] = $transfer_id->transfer_id;
     // Identify the Action and Process that caused this transaction
     $from['whaction_id'] = $to['whaction_id'] = $data['whaction_id'];
     if (isset($data['process_name'])) {
         $from['process_name'] = $to['process_name'] = $data['process_name'];
     }
     if (isset($data['process_id'])) {
         $from['process_id'] = $to['process_id'] = $data['process_id'];
     }
     // Now create the pair of transaction records from the input data
     foreach ($copyfields as $field) {
         $to[$field] = $item->{$field};
         $from[$field] = $item->{$field};
     }
     $from['qty'] = -$data['qty'];
     $to['qty'] = $data['qty'];
     if (isset($data['remarks'])) {
         $from['remarks'] = $to['remarks'] = $data['remarks'];
     }
     if (isset($data['status'])) {
         $from['status'] = $to['status'] = $data['status'];
     }
     $loctypes = array('whlocation_id', 'whbin_id');
     foreach ($loctypes as $type) {
         if (isset($data['from_' . $type])) {
             $from[$type] = $data['from_' . $type];
         }
         if (isset($data['to_' . $type])) {
             $to[$type] = $data['to_' . $type];
         }
     }
     if (isset($data['from_whlocation_id'])) {
         $whlocation = DataObjectFactory::Factory('WHLocation');
         $whlocation->load($data['from_whlocation_id']);
         if ($whlocation) {
             $from['glaccount_id'] = $whlocation->glaccount_id;
             $from['glcentre_id'] = $whlocation->glcentre_id;
             if (!empty($data['from_whbin_id']) && !WHBin::validBinLocation($data['from_whbin_id'], $data['from_whlocation_id'])) {
                 $errors[] = 'From Bin invalid for this location';
             }
         }
     }
     if (isset($data['to_whlocation_id'])) {
         $whlocation = DataObjectFactory::Factory('WHLocation');
         $whlocation->load($data['to_whlocation_id']);
         if ($whlocation) {
             $to['glaccount_id'] = $whlocation->glaccount_id;
             $to['glcentre_id'] = $whlocation->glcentre_id;
             if (!empty($data['to_whbin_id']) && !WHBin::validBinLocation($data['to_whbin_id'], $data['to_whlocation_id'])) {
                 $errors[] = 'To Bin invalid for this location';
             }
         }
     }
     // Set the balance to zero; the balance will be updated in the save
     $from['balance'] = $to['balance'] = 0;
     // Prepare the two transaction records for saving
     $from_model = DataObject::Factory($from, $errors, 'STTransaction');
     $to_model = DataObject::Factory($to, $errors, 'STTransaction');
     return array('from' => $from_model, 'to' => $to_model);
 }