Ejemplo n.º 1
0
 public function on_itt_return_icg_part($it)
 {
     //Update cost in workorder first
     $id = $it['checkout_to_id'];
     $woDbo = CalemFactory::getDbo('workorder');
     $woDbo->executeBySqlParam('select id from workorder where id=? for update', $id);
     $woRow = $woDbo->fetchById($id);
     $mc = $woRow['material_cost'] - $it['tran_total'];
     if ($mc < 0) {
         $mc = 0;
     }
     $mt = $mc + $woRow['labor_cost'];
     $woDbo->setValue('material_cost', $mc);
     $woDbo->setValue('total_cost', $mt);
     $woDbo->setIdForUpdate($id);
     $woDbo->update();
     //Update wop
     $wopDbo = CalemFactory::getDbo('wo_part');
     $ar = array();
     try {
         $rows = $wopDbo->fetchBySqlParam('select * from wo_part where wo_id=? and in_id=?', array($id, $it['in_id']));
         $row = $rows[0];
         $qn = $row['qty_used'] - $it['qty'];
         $ar['qty_used'] = $qn < 0 ? 0 : $qn;
         $ln = $row['line_cost'] - $it['tran_total'];
         $ar['line_cost'] = $ln < 0 ? 0 : $ln;
         $wopDbo->setChangeBulk($ar);
         $wopDbo->setIdForUpdate($row['id']);
         $wopDbo->update();
     } catch (CalemDboDataNotFoundException $ex) {
         //Add a new record
         //This is wrong, one is returning a part that's not checked out to workorder
         throw $ex;
     }
     //Update reserved parts if it's not closed.
     if ($woRow['status_id'] != 'wos_closed') {
         $rsvdBo = new CalemWoReservedBo();
         $rsvdBo->updateReservedSafe($woRow['id'], $it['in_id'], $it['qty']);
     }
     //Needs to update asset if wo is closed
     $assetHdlr = new CalemInTranNotifierAsset();
     $it['checkout_to_id'] = $woRow['asset_id'];
     $assetHdlr->on_itt_return_icg_part($it);
 }
Ejemplo n.º 2
0
 public function updateReserved($woId, $inId, $qty)
 {
     $rsvdBo = new CalemWoReservedBo();
     $rsvdBo->updateReservedSafe($woId, $inId, $qty);
 }
Ejemplo n.º 3
0
 public function onDataUpdated($baseTable, $baseCurrent, $baseUpdate, $customTable, $customCurrent, $customUpdate)
 {
     //Must have a status change
     if (isset($baseUpdate['status_id'])) {
         //Managing status changes
         if ($baseUpdate['status_id'] == 'wos_closed') {
             if ($baseCurrent['pm_id']) {
                 //Now update PM to set the date
                 $pmDbo = CalemFactory::getDbo('pm_asset');
                 $pmDbo->updateBySqlParam('update pm_asset set last_closed=? where pm_id=? and asset_id=?', array(CalemText::getServerDate(), $baseCurrent['pm_id'], $baseCurrent['asset_id']));
             }
             //Clear reserved
             $reserveBo = new CalemWoReservedBo();
             $reserveBo->removeReservedByWo($baseCurrent['id']);
         }
     }
     //Other listeners
     $this->notifyDataUpdated($baseTable, $baseCurrent, $baseUpdate, $customTable, $customCurrent, $customUpdate);
 }