Exemple #1
0
 public function save_partner($arr_partner = array(), $arr_partner_code = array())
 {
     if (empty($arr_partner) || !isset($arr_partner['type'])) {
         return false;
     }
     try {
         DB::start_transaction();
         //Arr_partner['type'] is value before form submit
         $arr_partner_code['ident'] = \Utility::partner_code($arr_partner['type']);
         $m_partner_code = \Model_Partnercode::forge($arr_partner_code);
         if ($m_partner_code->save()) {
             //Get ident and seq_no before partner_code save
             $ident = $m_partner_code->ident;
             $seq_no = sprintf("%'.05d", $m_partner_code->seq_no);
             $arr_partner['partner_code'] = $ident . $seq_no;
         } else {
             DB::rollback_transaction();
             return false;
         }
         $arr_partner['status'] = \Constants::$_status_partner['pending'];
         $arr_partner['created_at'] = date('Y-m-d H:i:s');
         $m_partner = Model_Mpartner::forge();
         $m_partner->is_new(true);
         $m_partner->set($arr_partner);
         if (!$m_partner->save()) {
             DB::rollback_transaction();
             return false;
         } else {
             DB::commit_transaction();
             return true;
         }
     } catch (Exception $ex) {
         DB::rollback_transaction();
         return false;
     }
 }
Exemple #2
0
 public static function find_ss_list($object, $flag = false)
 {
     $model_ss = new Model_Mss();
     $model_partner = new Model_Mpartner();
     $list_partner_code = array();
     if ($flag) {
         $list_partner = \Model_Mpartner::forge()->find($object);
     } else {
         $list_partner = $model_partner->get_info_by_userid($object);
     }
     $list_ss_id = array();
     foreach ($list_partner as $item) {
         $list_partner_code[] = $item['partner_code'];
     }
     if ($list_partner_code) {
         $config_partner['where'][] = array('partner_code', 'IN', $list_partner_code);
         $list_ss = \Model_Mss::forge()->find($config_partner);
         if ($list_ss) {
             foreach ($list_ss as $key => $val) {
                 $list_ss_id[] = $val->ss_id;
             }
         }
     }
     return $list_ss_id;
 }