Author Topic: Can´t change quantity to 0 from etc 2 with button (Physical count)  (Read 2746 times)

Nordi1984

  • Newbie
  • *
  • Posts: 4
Hi,

I´ve got some problem in inventory.

For example I got 2 pieces in the stock (Calem) and do a physical count and find that there is 0 of them. When I put 0 in the stock with the button (Physical conut) the system dosen´t change it. The parts have even a location. Is this a bug? I´ve try this in Calem Demo and even there is the same problem.

How to resolve this?

Any help would be greatly appreciated!
Thanks
Christoffer

Nordi1984

  • Newbie
  • *
  • Posts: 4
Re: Can´t change quantity to 0 from etc 2 with button (Physical count)
« Reply #1 on: September 17, 2010, 01:57:12 pm »
Hi,

I´ve resolve my own issue :)  Hope this will be useful for other that uses Calem Community.

I have printed "//Adjusted by CHNO" where the changes are.
This is the adjusted source code in CalemInTranBo.php:

   /**
    * Physical counting transaction (both part and tool are the same)
    * @param in_id - item id
    * @param location_id - stock location id
    * @param qty - qty to set to
    * @param costcode_id - costcode  
    * @param note - note
    * @param tran_time - time transaction happened
    * @param tran_user_id - who did the counting
    * @param store_user_id - staff performed the transaction
    *
    */   
   public function physical($tran, $rollback=false) {
      if ($this->logger->isInfoEnabled()) $this->logger->info("Physical transaction: " . var_export($tran, true));
      
      //Adjusted by CHNO, accept quantity = 0 in transaction table
      if ($tran['qty']<0) return;

      //Get valuation handler to find out unit cost                           
      $inDbo=CalemFactory::getDbo("inventory");
      $in=$inDbo->fetchById($tran['in_id']);
      
      try {
         //Now starts a transaction
         $inDbo->beginTransaction();
         
         //Lock inventory table first
         $inDbo->executeBySqlParam('select id from inventory where id=? for update', $tran['in_id']);
               
         //Update stock level
         $oldQty= $this->_setStock($inDbo, $tran['in_id'], $tran['location_id'], $tran['qty']);
         
         //Add inTransaction
         $inTranDbo=CalemFactory::getDbo('in_tran');
         $it['in_id']=$tran['in_id'];
         $it['type_id']= 'itt_physical';
         $it['location_id']=$tran['location_id'];

         //Adjusted by CHNO, if the user print 0 accept 0 and put it in transaction table      
         if ($tran['qty']==0){
         $it['qty']=0;
         }else{
         $it['qty']=$tran['qty'];
         }

         $it['qty_orig']=$oldQty;
         $it['costcode_id']=isset($tran['costcode_id']) ? $tran['costcode_id'] : null;
         $it['note']=isset($tran['note'])? $tran['note'] : null;
         $it['tran_time']=$tran['tran_time'];
         $it['tran_user_id']=isset($tran['tran_user_id']) ? $tran['tran_user_id'] : null;
         $it['store_user_id']=isset($tran['store_user_id']) ? $tran['store_user_id'] : null;
         //Generating a unique id
         $it['id']=$inTranDbo->getUid();
         $inTranDbo->setChangeBulk($it);
         $inTranDbo->insert();
         
         //Notify transactions
         $this->notify($this->conf['physical']['notifier_list'], $it);
         
         //Review order, etc.
         $this->inBo->onInStockLevelChanged($tran['in_id'], $inDbo);
         
         //Commit transaction
         $inDbo->commit();
         return $it;
      
      }catch (Exception $ex) {
         if ($rollback) $inDbo->rollback();
         $this->logger->error('Error in check out transaction: ' . $ex->getMessage() . ', tran=' . var_export($tran, true));
         throw $ex;
      }                                          
   }   



Nordi1984

  • Newbie
  • *
  • Posts: 4
Re: Can´t change quantity to 0 from etc 2 with button (Physical count)
« Reply #2 on: September 17, 2010, 02:01:54 pm »
Here´s the next source code in CalemInTranBo.php that most be changed to make it work.
Even here have I printed "//Adjusted by CHNO" were the change are.


   /**
    * Set stock level
    */
   private function _setStock($inDbo, $in_id, $location_id, $qty) {
      //Adjust stock level
      $oldQty=0;
      $stockDbo=CalemFactory::getDbo('in_stock');
      try {
         $stocks=$stockDbo->fetchBySqlParam('select * from in_stock where in_id=? and location_id=?',
               array($in_id, $location_id));

         $stockRow=$stocks[0];
         $oldQty=$stockRow['qty'];

         //Adjusted by CHNO, if the user print 0 accept 0 and put it in stock table
         if ($qty==0){
         $stockDbo->setValue('qty', 0);
         }else{
         $stockDbo->setValue('qty', $qty);
         }

         $stockDbo->setIdForUpdate($stockRow['id']);
         $stockDbo->update();
         
      } catch (CalemDboDataNotFoundException $ex) {
         //Add a new location here.
         $ar=array();
         $ar['in_id']=$in_id;
         $ar['location_id']=$location_id;
         $ar['qty']=$qty;
         $stockDbo->setChangeBulk($ar);
         $stockDbo->insert();   
      }
      //Re-calculate stock level
      $sc=$inDbo->getCountBySqlParam('select sum(qty) from in_stock where in_id=?', array($in_id));
      $inDbo->setValue('qty_in_stock', $sc);
      $inDbo->setIdForUpdate($in_id);
      $inDbo->update();   
      return $oldQty;
   }