/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $validation = Validate::DealValidation(Input::all()); if ($validation->fails()) { return Redirect::to('ofertas/create')->withErrors($validation)->withInput(); } else { $deal = new Deal(); $deal->title = Input::get('title'); $deal->description = Input::get('description'); $deal->image = ""; $deal->from = Input::get('from'); $deal->to = Input::get('to'); $deal->price = Input::get('price'); $deal->save(); mkdir("img/deals/" . $deal->id, 0700); $destinationPath = 'img/deals/' . $deal->id; $filename = $deal->id . "." . Input::file('image')->getClientOriginalExtension(); Input::file('image')->move($destinationPath, $filename); $deal2 = Deal::find($deal->id); $deal2->image = 'img/deals/' . $deal->id . "/" . $filename; $deal2->save(); return Redirect::to('ofertas'); } }
private function saveProduction(Deal $model) { $deal = isset($_POST['Deal']) ? $_POST['Deal'] : false; $features = isset($deal['feature']) ? array_keys($deal['feature']) : []; $hasErrors = false; if ($deal) { $model->attributes = $deal; if (isset($_POST['textCustomFeature']) && $_POST['textCustomFeature']) { $customFeature = $this->createCustomFeature($_POST['textCustomFeature']); if ($customFeature->save()) { $features[] = $customFeature->fea_id; } else { Yii::app()->user->setFlash('custom-feature-error', 'Custom feature could not be saved. Contact administrator'); $hasErrors = true; } } if (!$model->setFeatures($features)) { Yii::app()->user->setFlash('feature-error', 'Features could not be updated'); $hasErrors = true; } if (isset($deal['video']) && $deal['video']) { $this->saveVideo($model->dea_id, $deal['video']); } /** * taking advantage of lazy operators. We first validate (to get all validation errors. * Then if there were none we check if something happened before, like custom feature was not saved. * finaly if there were no errors before we save the model. */ if ($model->validate() && !$hasErrors && $model->save()) { return true; } } return false; }
public function actionCreate() { IsAuth::Admin(); $model = new Deal(); if (isset($_POST['Deal'])) { $model->date_added = new CDbExpression('NOW()'); $model->attributes = $_POST['Deal']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->deal_id)); } } $this->render('create', array('model' => $model)); }
public function testSaveDelete() { Deal::truncate(); $d = new Deal(); $d->name = "asasdasd"; $d->save(); $this->assertTrue($d->id != 0); $this->assertTrue($d->created != null); $this->assertTrue($d->updated != null); // $this->assertTrue($rp["deleted"] == 0); $d->delete(); $this->assertTrue($d->deleted == 1); Deal::truncate(); }
public function actionCreate($company_id) { $Deal = new Deal(); $Company = Company::model()->findByPk($company_id); if (isset($_POST['Deal'])) { $Deal->setAttributes($_POST['Deal'], false); $Deal->from_company_id = Yii::app()->getUser()->getProfile()->company->id; $Deal->to_company_id = $company_id; if ($Deal->validate()) { $Deal->save(); $this->redirect('/cabinet/deal/'); } } $this->render('create', ['Deal' => $Deal, 'Company' => $Company]); }
public function postSavedeal() { $user_id = Session::get('user_id'); $deal = new Deal(); //'ro_amount':ro_amount,'ro_date':ro_date,'executive_id':executive_id,'payment_peference':payment_peference,'remark':remark,}, $deal->client_id = Input::get('client_id'); $deal->agency_id = Input::get('agency_id'); $deal->ro_number = Input::get('ro_number'); $deal->ro_date = Input::get('ro_date'); $deal->ro_amount = Input::get('ro_amount'); $deal->executive_id = Input::get('executive_id'); $deal->payment_peference = Input::get('payment_peference'); $deal->remarks = Input::get('remark'); $deal->user_id = $user_id; $deal->save(); $id = $deal->id; //echo $id; $itemList = Input::get('itemList'); for ($count = 0; $count < count($itemList); $count++) { $dealdetails = new DealDetails(); $dealdetails->deal_id = $id; $dealdetails->item_id = $itemList[$count]['property_id']; $dealdetails->start_time = $itemList[$count]['start_time']; $dealdetails->end_time = $itemList[$count]['end_time']; $dealdetails->from_date = $itemList[$count]['from_date']; $dealdetails->to_date = $itemList[$count]['to_date']; $dealdetails->units = $itemList[$count]['units']; $dealdetails->rate = $itemList[$count]['rate']; $dealdetails->amount = $itemList[$count]['amount']; $dealdetails->save(); } // $deal->from_date = Input::get ( 'from_date' ); //$deal->to_date = Input::get ( 'to_date' ); //$deal->rate = Input::get ( 'rate' ); // $deal->duration = Input::get ( 'duration' ); //$deal->executive_id = Input::get ( 'executive_id' ); //$deal->time_slot = implode(',', Input::get('time_slot')); //$deal->item_id = Input::get ( 'item_id' ); // $deal->save (); return Response::json($deal); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); $this->setLayout(false); // first api only accepts posts if ($request->getMethod() != "POST") { $this->getResponse()->setStatusCode(405); return $this->renderPartial("wrong_method"); } $access_token = $request->getParameter("access_token"); // check access token if (!$access_token) { $this->getResponse()->setStatusCode(401); return $this->renderPartial("authentication_error"); } $user = Doctrine_Core::getTable('sfGuardUser')->createQuery('u')->where('u.access_token = ?', $access_token)->addWhere('u.is_active = ?', true)->fetchOne(); // check access token if (!$user) { $this->getResponse()->setStatusCode(401); return $this->renderPartial("authentication_error"); } // check if account was setup properly // @todo add publisher commission if (!$user->getApiPriceLike() || !$user->getApiPriceMediaPenetration() || !$user->getApiPaymentMethod() || !$user->getApiCommissionPercentage()) { $this->getResponse()->setStatusCode(403); return $this->renderPartial("setup_failure"); } // get json post $json_content = file_get_contents("php://input"); sfContext::getInstance()->getLogger()->notice($json_content); $deal = new Deal(); $deal->setSfGuardUser($user); $deal->setPaymentMethod($user->getApiPaymentMethod()); $data = json_decode($json_content, true); // check if data is valid json if (!$data) { $this->getResponse()->setStatusCode(406); return $this->renderPartial("wrong_mimetype"); } $deal->fromApiArray($data); // set commission values $deal->setCommissionPercentage($user->getApiCommissionPercentage()); $pot = round($deal->getPrice() * $user->getApiCommissionPercentage() / 100, 2, PHP_ROUND_HALF_UP); $deal->setCommissionPot($pot); $unit = round($pot / $deal->getTargetQuantity(), 2, PHP_ROUND_HALF_UP); $deal->setCommissionPerUnit($unit); // validate request $validate = $deal->validate(); if ($validate !== true) { $this->getResponse()->setStatusCode(406); return $this->renderPartial("deals/wrong_fields", array("errors" => $validate)); } else { $deal->save(); $deal->complete_campaign(); $deal->complete_share(); $deal->complete_coupon(); $deal->complete_billing(); $deal->submit(); if (array_key_exists('activate', $data) && $data['activate'] === true) { $deal->approve(); } } }
public function postBook() { $response = null; $Bill = null; $spa_id = Input::get('spaName'); $outlet_id = Input::get('spaLocation'); $service_id = Input::get('serviceName'); $apptDate = Input::get('apptDate'); $apptTime = Input::get('timeSlot'); if (!empty($spa_id) && !empty($outlet_id) && !empty($service_id) && !empty($apptDate)) { $apptDateTime = strtotime($apptDate . " " . $apptTime); $service = Service::find($service_id); $response = array("retailerName" => Retailer::find($spa_id)->name, "outletName" => Outlet::find($outlet_id)->name, "serviceName" => $service->name . " (" . $service->time_operate . " mins)", "apptDateTime" => $apptDateTime, "price" => $service->price); if (!Auth::user()) { return View::make('site/user/book', compact('response', 'Bill')); } $deal = Deal::where('service_id', '=', $service_id)->where('deal_type', '=', 'Service')->first(); if ($deal == null) { $deal = new Deal(); $deal->service_id = $service_id; $deal->deal_type = 'Service'; $deal->title = $service->name; $deal->amount = $service->price; $deal->discount = 0; $deal->special_request = ""; $deal->status = "active"; $deal->save(); } $Bill = new DealTransaction(); $Bill->deal_id = $deal->id; $Bill->consumer_id = Auth::user()->id; $Bill->consumer_email = Auth::user()->email; $Bill->qty = 1; $Bill->amount = $service->price; $Bill->total = $service->price; $Bill->save(); return View::make('site/user/book', compact('response', 'Bill')); } return Redirect::to('/'); }
/** * makes a full copy of an instruction * * @param string $type * @param string $status * @return bool|\Deal * @throws InvalidArgumentException */ public function copyAs($type = self::TYPE_SALES, $status = self::STATUS_PRODUCTION) { if (!in_array($type, [self::TYPE_LETTINGS, self::TYPE_SALES])) { throw new InvalidArgumentException('type must be one of the following [' . self::TYPE_LETTINGS . ', ' . self::TYPE_SALES . '] actual value is: ' . $type); } if (!in_array($status, self::getStatuses())) { throw new InvalidArgumentException('Status must be in the list [' . implode(', ', self::getStatuses()) . '] actual value is: ' . $status); } /** @var $property Property */ $property = Property::model()->findByPk($this->dea_prop); $instruction = new Deal('copy'); $instruction->setAttributes($this->attributes); $instruction->dea_type = $type; $instruction->dea_status = $status; $instruction->dea_marketprice = 0; $instruction->dea_launchdate = null; $instruction->importFromProperty($property); if ($instruction->save(false)) { InstructionVideo::copyRecords($this->dea_id, $instruction->dea_id); LinkInstructionToFeature::copyRecords($this->dea_id, $instruction->dea_id); LinkClientToInstruction::copyRecords($this->dea_id, $instruction->dea_id); Media::copyRecords($this->dea_id, $instruction->dea_id); return $instruction; } return false; }
public function actionSelectInstruction() { $builder = AppointmentBuilder::getCurrent(); if (isset($_POST['Deal']) && $_POST['Deal']) { // need to finish instruction info; $instruction = Deal::model()->findByPk($builder->getInstructionId()); $instruction->attributes = $_POST['Deal']; if ($instruction->save()) { $this->redirect(['InstructionSelected', 'instructionId' => $instruction->dea_id]); } else { echo "<pre style='color:blue' title='" . __FILE__ . "'>" . basename(__FILE__) . ":" . __LINE__ . "<br>"; print_r($instruction->getErrors()); echo "</pre>"; } $this->render('createInstruction', ['model' => $instruction]); return; } /** @var $property Property */ $property = Property::model()->findByPk($builder->getPropertyId()); if (!$property->instructions || isset($_GET['new'])) { // need to create one. $instruction = new Deal(); $instruction->dea_prop = $property->pro_id; $instruction->dea_status = Deal::STATUS_VALUATION; $instruction->importFromProperty($property); $instruction->save(false); $builder->setInstructionId($instruction->dea_id); $this->render('createInstruction', ['model' => $instruction]); return; } $this->render('selectInstruction', ['model' => $property]); }
private static function makeDealsWith(Deal $deal) { $order = new Order(); $order->findById($deal->getOrderId()); if ($order->getType() == OrderType::SELL) { $oppositeDeals = Deal::getOpenedBuyDeals($order->getPrice(), $order->getRateId()); } else { $oppositeDeals = Deal::getOpenedSellDeals($order->getPrice(), $order->getRateId()); } foreach ($oppositeDeals as $oppDeal) { $oppositeDeal = new Deal(); $oppositeDeal->findById($oppDeal['id']); $oppositeOrder = new Order(); $oppositeOrder->findById($oppositeDeal->getOrderId()); $difference = $deal->getVolume() - $oppositeDeal->getVolume(); if ($difference == 0) { $deal->setPrice($oppositeDeal->getPrice()); $deal->setDone(1); $deal->save(); $order->setPart(1.0); $order->setStatus(OrderStatus::DONE); $order->save(); $oppositeDeal->setDone(1); $oppositeDeal->setDate($deal->getDate()); $oppositeDeal->save(); $oppositeOrder->setPart(1.0); $oppositeOrder->setStatus(OrderStatus::DONE); $oppositeOrder->setDate($deal->getDate()); $oppositeOrder->save(); self::transferMoney($deal, $oppositeDeal); break; } $intermediateDeal = new Deal(); $intermediateDeal->setRateId($order->getRateId()); $intermediateDeal->setDate($deal->getDate()); $intermediateDeal->setDone(1); if ($difference < 0) { $deal->setPrice($oppositeDeal->getPrice()); $deal->setDone(1); $deal->save(); $order->setPart(1.0); $order->setStatus(OrderStatus::DONE); $order->save(); $intermediateDeal->setOrderId($oppositeOrder->getId()); $intermediateDeal->setUserId($oppositeOrder->getUserId()); $intermediateDeal->setType($oppositeOrder->getType()); $intermediateDeal->setPrice($oppositeDeal->getPrice()); $intermediateDeal->setVolume($deal->getVolume()); $intermediateDeal->insert(); $oppositeOrder->updatePart(); $oppositeOrder->setDate($deal->getDate()); $oppositeOrder->save(); $oppositeDeal->setVolume(-$difference); $oppositeDeal->setDate($deal->getDate()); $oppositeDeal->save(); self::transferMoney($deal, $intermediateDeal); break; } else { $deal->setVolume($difference); $deal->save(); $intermediateDeal->setOrderId($order->getId()); $intermediateDeal->setUserId($order->getUserId()); $intermediateDeal->setType($order->getType()); $intermediateDeal->setPrice($oppositeDeal->getPrice()); $intermediateDeal->setVolume($oppositeDeal->getVolume()); $intermediateDeal->insert(); $order->updatePart(); $order->save(); $oppositeDeal->setDone(1); $oppositeDeal->setDate($deal->getDate()); $oppositeDeal->save(); $oppositeOrder->setPart(1.0); $oppositeOrder->setStatus(OrderStatus::DONE); $oppositeOrder->setDate($deal->getDate()); $oppositeOrder->save(); self::transferMoney($intermediateDeal, $oppositeDeal); } } }
public function testAcceptedOfferIsOverridenByNewerInstruction() { $instruction = new Deal(); $instruction->dea_prop = $this->property->pro_id; $instruction->dea_status = 'Completed'; $instruction->save(false); $sql = "INSERT INTO link_client_to_instruction (dealId, clientId, capacity)\n\t\t\t\tVALUES\n\t\t\t\t(" . $instruction->dea_id . ", " . $this->owner1->cli_id . ", 'Owner'),\n\t\t\t\t(" . $instruction->dea_id . ", " . $this->owner2->cli_id . ", 'Owner')"; Yii::app()->db->createCommand($sql)->execute(); $sql = "INSERT INTO offer SET\n\t\toff_deal = '" . $instruction->dea_id . "',\n\t \toff_status = 'Accepted'"; Yii::app()->db->createCommand($sql)->execute(); $offerId = Yii::app()->db->getLastInsertID(); $sql = "INSERT INTO cli2off SET c2o_cli = '" . $this->owner3->cli_id . "', c2o_off='" . $offerId . "'"; Yii::app()->db->createCommand($sql)->execute(); $sql = "INSERT INTO cli2off SET c2o_cli = '" . $this->owner4->cli_id . "', c2o_off='" . $offerId . "'"; Yii::app()->db->createCommand($sql)->execute(); // ================================================================================= // <<< second instruction $instruction2 = new Deal(); $instruction2->dea_prop = $this->property->pro_id; $instruction2->dea_status = 'Available'; $instruction2->save(false); $sql = "INSERT INTO link_client_to_instruction (dealId, clientId, capacity)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t(" . $instruction2->dea_id . ", " . $this->owner1->cli_id . ", 'Owner'),\n\t\t\t\t\t\t(" . $instruction2->dea_id . ", " . $this->owner2->cli_id . ", 'Owner')"; Yii::app()->db->createCommand($sql)->execute(); // second instruction >>> // ================================================================================= $this->migration->up(); $property = Property::model()->findByPk($this->property->pro_id); $this->assertCount(2, $property->owners); $ownerIds = []; foreach ($property->owners as $key => $value) { $ownerIds[] = $value->cli_id; } $this->assertContains($this->owner1->cli_id, $ownerIds); $this->assertContains($this->owner2->cli_id, $ownerIds); }