Example #1
0
 private function getOrderId($postedData, $type, $isnew, $fldname = 'qoi_id'){
     $newid = "-1";
     if(!$this->isordridauto){
         if($postedData->isconvert){
             $newid = $postedData->newid;
         }else{
             $newid = $postedData->$fldname;
         }
         if(!isset($newid)){
             $newid = "-1";
         }
         return $newid;
     }else{
         if($isnew || $postedData->isconvert){
             $conditions = array('forwhat=? AND foryear=? AND formonth=?', $type, $this->curyear, $this->curmonth);
             $select = 'lastid';
             $result = \Idmaster::find('all', array('select' => $select
                         , 'conditions' => $conditions));
             $newid = $this->curyear . '/' . $this->curmonth . '/';
             switch($type){
                 case Menu::ord_type_quote:
                     $staticstr = $this->qotid_static_str;
                 break;
                 case Menu::ord_type_order:
                     $staticstr = $this->ordrid_static_str;
                 break;
                 case Menu::ord_type_invoice:
                     $staticstr = $this->invid_static_str;
                 break;
             }
             $newid .= $staticstr;
             if(count($result) > 0){
                 foreach ($result as &$rec) {
                     $tmpid = $rec->lastid + 1;
                     $newid .= sprintf('%05d',$tmpid);
                     break;
                 }
             }else{
                 $tmpid = 1;
                 $newid .= sprintf('%05d',$tmpid);
             }
         }else{
             $newid = $postedData->$fldname;
         }
     }
     return $newid;
 }
Example #2
0
    public function updateOrderAutoId($newId)
    {
        list($year, $month, $id) = explode("/", $newId);
        $tmpType = substr($id, 0, 3);
        $forwhat = '';
        switch(strtolower($tmpType))
        {
            case strtolower(Helper::CONST_qotid_static_str):
                $forwhat = Helper::CONST_Quote;
                break;
            case strtolower(Helper::CONST_odrid_static_str):
                $forwhat = Helper::CONST_Order;
                break;
            case strtolower(Helper::CONST_invid_static_str):
                $forwhat = Helper::CONST_Invoice;
                break;
        }
        $lastId = substr($id, strlen($tmpType));
        
        $condition = 'forwhat="' . $forwhat . '"';
        $condition .= ' AND foryear = ' . $year;
        $condition .= ' AND formonth = ' . $month;

        $criteria = new CDbCriteria;
        $criteria->condition = $condition;
        $result = Idmaster::model()->findAll( $criteria );                
        if(count($result) > 0)
        {
            $idmastermodel = $result[0];
        }
        else
        {
            $idmastermodel = new Idmaster;
        }
        $idmastermodel->foryear = $year;
        $idmastermodel->formonth = $month;
        $idmastermodel->forwhat = $forwhat;
        $idmastermodel->lastid = $lastId;
        
        return $idmastermodel->save();
    }
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=Idmaster::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}