Example #1
0
 public function setOfferOut($offerin_id, $category, $reselleremployee_id, array $articles)
 {
     $reselleremployee = Model::Reselleremployee()->find($reselleremployee_id);
     $offerin = Model::Offerin()->find($offerin_id);
     if ($reselleremployee && $offerin) {
         $check = Model::Offerout()->where(['reselleremployee_id', '=', $reselleremployee_id])->where(['offerin_id', '=', $offerin_id])->where(['category', '=', $category])->count();
         if ($check > 0) {
             return 0;
         }
         $offer = Model::Offerout()->create(['status_id' => getStatus('NOT_COMPLETED'), 'reseller_id' => $reselleremployee->reseller_id, 'reselleremployee_id' => $reselleremployee_id, 'offerin_id' => $offerin_id, 'category' => $category, 'zip' => $offerin->zip, 'company_id' => $offerin->company_id, 'people_id' => $offerin->people_id, 'date_offerin' => $offerin->date, 'expiration_offerin' => $offerin->expiration, 'global' => $offerin->global, 'statusofferin' => $offerin->status_id, 'market' => $offerin->market, 'universe' => $offerin->universe])->save();
         foreach ($articles as $articlein_id) {
             $article = Model::Articlein()->find($articlein_id);
             if ($article) {
                 if ($article->offerin_id == $offerin_id) {
                     $a = $article->assoc();
                     unset($a['id']);
                     unset($a['created_at']);
                     unset($a['updated_at']);
                     unset($a['deleted_at']);
                     $a['offerout_id'] = $offer->id;
                     $a['price'] = 0;
                     if ($a['item_id'] > 0) {
                         $seg = jmodel('segment')->find($a['item_id']);
                         if ($seg) {
                             $a['name'] = $seg->name;
                         }
                     }
                     Model::Articleout()->create($a)->save();
                 } else {
                     $offer->delete();
                     return 'Article inexistant';
                 }
             } else {
                 $offer->delete();
                 return 'Article inexistant';
             }
         }
         return $offer->id;
     } else {
         return 'offre inconnue';
     }
 }