/**
  * @return null
  */
 protected function buildForm()
 {
     if (null === ($data = DpdPickup::getConfigValue('default_status'))) {
         $data = DpdPickup::NO_CHANGE;
     }
     $this->formBuilder->add('default_status', 'choice', ['label' => $this->translator->trans('Change order status to', [], DpdPickup::DOMAIN), 'choices' => [DpdPickup::NO_CHANGE => $this->translator->trans("Do not change", [], DpdPickup::DOMAIN), DpdPickup::PROCESS => $this->translator->trans("Set orders status as processing", [], DpdPickup::DOMAIN), DpdPickup::SEND => $this->translator->trans("Set orders status as sent", [], DpdPickup::DOMAIN)], 'required' => true, 'expanded' => true, 'multiple' => false, 'data' => $data]);
 }
 protected function buildForm()
 {
     if (null === ($data = DpdPickup::getConfigValue('default_status'))) {
         $data = DpdPickup::NO_CHANGE;
     }
     $this->formBuilder->add('new_status_id', 'choice', array('label' => Translator::getInstance()->trans('Change order status to', [], DpdPickup::DOMAIN), 'choices' => array(DpdPickup::NO_CHANGE => Translator::getInstance()->trans("Do not change", [], DpdPickup::DOMAIN), DpdPickup::PROCESS => Translator::getInstance()->trans("Set orders status as processing", [], DpdPickup::DOMAIN), DpdPickup::SEND => Translator::getInstance()->trans("Set orders status as sent", [], DpdPickup::DOMAIN)), 'required' => true, 'expanded' => true, 'multiple' => false, 'data' => $data))->add('order_ref_check', 'collection', array('type' => 'checkbox', 'allow_add' => true, 'allow_delete' => true))->add('order_ref', 'collection', array('type' => 'text', 'allow_add' => true, 'allow_delete' => true))->add('assur', 'collection', array('type' => 'checkbox', 'allow_add' => true, 'allow_delete' => true))->add('pkgNumber', 'collection', array('type' => 'number', 'allow_add' => true, 'allow_delete' => true))->add('pkgWeight', 'collection', array('type' => 'number', 'allow_add' => true, 'allow_delete' => true));
 }
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === DpdPickup::getModuleId()) {
         if ($event->getOrder()->getStatusId() === DpdPickup::STATUS_SENT) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_icirelais')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_icirelais'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $this->parser->assign('order_date', $order->getCreatedAt());
                 $this->parser->assign('update_date', $order->getUpdatedAt());
                 $this->parser->assign('package', $order->getDeliveryRef());
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }
 public function parseResults(LoopResult $loopResult)
 {
     $icirelaiskey = DpdPickup::getModuleId();
     $loopResult = parent::parseResults($loopResult);
     for ($loopResult->rewind(); $loopResult->valid(); $loopResult->next()) {
         $loopResult->current()->set("ICI_RELAIS_MODULE", $icirelaiskey);
     }
     return $loopResult;
 }
 public function buildArray()
 {
     $path = ExportExaprint::getJSONpath();
     if (is_readable($path) && ($order = OrderQuery::create()->findOneByRef($this->getRef())) !== null && $order->getDeliveryModuleId() === DpdPickup::getModuleId()) {
         $json = json_decode(file_get_contents($path), true);
         return array($this->getRef() => $json['expcode']);
     } else {
         return array();
     }
 }
 public function buildArray()
 {
     $area = $this->getArea();
     $prices = DpdPickup::getPrices();
     if (!isset($prices[$area]) || !isset($prices[$area]["slices"])) {
         return array();
     }
     $areaPrices = $prices[$area]["slices"];
     ksort($areaPrices);
     return $areaPrices;
 }
 /**
  * This function supposes that delivery ref is always in the 17th column
  */
 public function importFile()
 {
     $i = 0;
     $con = Propel::getWriteConnection(OrderTableMap::DATABASE_NAME);
     $con->beginTransaction();
     $form = $this->createForm('dpdpickup.import');
     try {
         $vForm = $this->validateForm($form);
         // Get file
         $importedFile = $vForm->getData()['import_file'];
         // Check extension
         if (!in_array(strtolower($importedFile->getClientOriginalExtension()), ['csv', 'txt'])) {
             throw new FormValidationException(Translator::getInstance()->trans('Bad file format. Plain text or CSV expected.', [], DpdPickup::DOMAIN));
         }
         $csvData = file_get_contents($importedFile);
         $lines = explode(PHP_EOL, $csvData);
         // For each line, parse columns
         foreach ($lines as $line) {
             $parsedLine = str_getcsv($line, "\t");
             // Check if there are enough columns to include order ref
             if (count($parsedLine) > DpdPickup::ORDER_REF_COLUMN) {
                 // Get delivery and order ref
                 $deliveryRef = $parsedLine[DpdPickup::DELIVERY_REF_COLUMN];
                 $orderRef = $parsedLine[DpdPickup::ORDER_REF_COLUMN];
                 // Save delivery ref if there is one
                 if (!empty($deliveryRef)) {
                     $this->importDeliveryRef($deliveryRef, $orderRef, $i);
                 }
             }
         }
         $con->commit();
         // Get number of affected rows to display
         $this->getSession()->getFlashBag()->add('update-orders-result', Translator::getInstance()->trans('Operation successful. %i orders affected.', ['%i' => $i], DpdPickup::DOMAIN));
         // Redirect
         return $this->generateRedirect(URL::getInstance()->absoluteUrl($form->getSuccessUrl(), ['current_tab' => 'import_exaprint']));
     } catch (FormValidationException $e) {
         $con->rollback();
         $this->setupFormErrorContext(null, $e->getMessage(), $form);
         return $this->render('module-configure', ['module_code' => DpdPickup::getModuleCode(), 'current_tab' => 'import_exaprint']);
     }
 }
 public function configureAction()
 {
     if (null !== ($response = $this->checkAuth([AdminResources::MODULE], ['DpdPickup'], [AccessManager::CREATE, AccessManager::UPDATE]))) {
         return $response;
     }
     $baseForm = $this->createForm("dpdpickup.config.form");
     $errorMessage = null;
     try {
         $form = $this->validateForm($baseForm);
         $data = $form->getData();
         // Save data
         DpdPickup::setConfigValue('default_status', $data["default_status"]);
     } catch (FormValidationException $ex) {
         $errorMessage = $this->createStandardFormValidationErrorMessage($ex);
     } catch (\Exception $ex) {
         $errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], DpdPickup::DOMAIN);
     }
     if ($errorMessage !== null) {
         $this->setupFormErrorContext(Translator::getInstance()->trans("Error while updating status", [], DpdPickup::DOMAIN), $errorMessage, $baseForm);
     }
     return $this->generateRedirectFromRoute("admin.module.configure", [], ['module_code' => "DpdPickup", 'current_tab' => "config", '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction']);
 }
 public function export()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('DpdPickup'), AccessManager::UPDATE))) {
         return $response;
     }
     $form = new ExportExaprintForm($this->getRequest());
     $error_message = null;
     try {
         $vform = $this->validateForm($form);
         $file_path = self::getJSONpath();
         if (file_exists($file_path) ? is_writable($file_path) : is_writable(__DIR__ . "/../Config/")) {
             $file = fopen(self::getJSONpath(), 'w');
             fwrite($file, json_encode(array("name" => $vform->get('name')->getData(), "addr" => $vform->get('addr')->getData(), "addr2" => $vform->get('addr2')->getData(), "zipcode" => $vform->get('zipcode')->getData(), "city" => $vform->get('city')->getData(), "tel" => $vform->get('tel')->getData(), "mobile" => $vform->get('mobile')->getData(), "mail" => $vform->get('mail')->getData(), "expcode" => $vform->get('expcode')->getData())));
             fclose($file);
             return $this->generateRedirectFromRoute("admin.module.configure", [], ['module_code' => "DpdPickup", 'current_tab' => "configure_export_exaprint", '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction']);
         } else {
             throw new \Exception(Translator::getInstance()->trans("Can't write DpdPickup/Config/exportdat.json. Please change the rights on the file and/or the directory.", [], DpdPickup::DOMAIN));
         }
     } catch (\Exception $e) {
         $error_message = $e->getMessage();
     }
     $this->setupFormErrorContext('erreur export fichier exaprint', $error_message, $form);
     return $this->render('module-configure', ['module_code' => DpdPickup::getModuleCode(), 'current_tab' => "configure_export_exaprint"]);
 }
 protected function check_module($id)
 {
     return $id == DpdPickup::getModuleId();
 }
Exemple #11
0
 public function exportfile()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('DpdPickup'), AccessManager::UPDATE))) {
         return $response;
     }
     if (is_readable(ExportExaprint::getJSONpath())) {
         $admici = json_decode(file_get_contents(ExportExaprint::getJSONpath()), true);
         $keys = array("name", "addr", "zipcode", "city", "tel", "mobile", "mail", "expcode");
         $valid = true;
         foreach ($keys as $key) {
             $valid &= isset($admici[$key]) && ($key === "assur" ? true : !empty($admici[$key]));
         }
         if (!$valid) {
             return Response::create(Translator::getInstance()->trans("The file DpdPickup/Config/exportdat.json is not valid. Please correct it.", [], DpdPickup::DOMAIN), 500);
         }
     } else {
         return Response::create(Translator::getInstance()->trans("Can't read DpdPickup/Config/exportdat.json. Did you save the export information ?", [], DpdPickup::DOMAIN), 500);
     }
     $exp_name = $admici['name'];
     $exp_address1 = $admici['addr'];
     $exp_address2 = isset($admici['addr2']) ? $admici['addr2'] : "";
     $exp_zipcode = $admici['zipcode'];
     $exp_city = $admici['city'];
     $exp_phone = $admici['tel'];
     $exp_cellphone = $admici['mobile'];
     $exp_email = $admici['mail'];
     $exp_code = $admici['expcode'];
     $res = self::harmonise('$' . "VERSION=110", 'alphanumeric', 12) . "\r\n";
     $orders = OrderQuery::create()->filterByDeliveryModuleId(DpdPickup::getModuleId())->find();
     // FORM VALIDATION
     $form = new ExportExaprintSelection($this->getRequest());
     $status_id = null;
     try {
         $vform = $this->validateForm($form);
         $status_id = $vform->get("new_status_id")->getData();
         if (!preg_match("#^nochange|processing|sent\$#", $status_id)) {
             throw new \Exception("Invalid status ID. Expecting nochange or processing or sent");
         }
     } catch (\Exception $e) {
         Tlog::getInstance()->error("Form dpdpickup.selection sent with bad infos. ");
         return Response::create(Translator::getInstance()->trans("Got invalid data : %err", ['%err' => $e->getMessage()], DpdPickup::DOMAIN), 500);
     }
     // For each selected order
     /** @var Order $order */
     foreach ($orders as $order) {
         $orderRef = str_replace(".", "-", $order->getRef());
         $collectionKey = array_search($orderRef, $vform->getData()['order_ref']);
         if (false !== $collectionKey && array_key_exists($collectionKey, $vform->getData()['order_ref_check']) && $vform->getData()['order_ref_check'][$collectionKey]) {
             // Get if the package is assured, how many packages there are & their weight
             $assur_package = array_key_exists($collectionKey, $vform->getData()['assur']) ? $vform->getData()['assur'][$collectionKey] : false;
             $pkgNumber = array_key_exists($collectionKey, $vform->getData()['pkgNumber']) ? $vform->getData()['pkgNumber'][$collectionKey] : null;
             $pkgWeight = array_key_exists($collectionKey, $vform->getData()['pkgWeight']) ? $vform->getData()['pkgWeight'][$collectionKey] : null;
             // Check if status has to be changed
             if ($status_id == "processing") {
                 $event = new OrderEvent($order);
                 $status = OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PROCESSING);
                 $event->setStatus($status->getId());
                 $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
             } elseif ($status_id == "sent") {
                 $event = new OrderEvent($order);
                 $status = OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_SENT);
                 $event->setStatus($status->getId());
                 $this->getDispatcher()->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
             }
             //Get invoice address
             $address = OrderAddressQuery::create()->findPK($order->getInvoiceOrderAddressId());
             //Get Customer object
             $customer = CustomerQuery::create()->findPK($order->getCustomerId());
             //Get OrderAddressDpdPickup object
             $icirelais_code = OrderAddressIcirelaisQuery::create()->findPK($order->getDeliveryOrderAddressId());
             if ($icirelais_code !== null) {
                 // Get Customer's cellphone
                 if (null == ($cellphone = $address->getCellphone())) {
                     $address->getPhone();
                 }
                 //Weight & price calc
                 $price = 0;
                 $price = $order->getTotalAmount($price, false);
                 // tax = 0 && include postage = flase
                 $pkgWeight = floor($pkgWeight * 100);
                 $assur_price = $assur_package == 'true' ? $price : 0;
                 $date_format = date("d/m/y", $order->getUpdatedAt()->getTimestamp());
                 $res .= self::harmonise($order->getRef(), 'alphanumeric', 35);
                 // Order ref
                 $res .= self::harmonise("", 'alphanumeric', 2);
                 $res .= self::harmonise($pkgWeight, 'numeric', 8);
                 // Package weight
                 $res .= self::harmonise("", 'alphanumeric', 15);
                 $res .= self::harmonise($address->getLastname(), 'alphanumeric', 35);
                 // Charged customer
                 $res .= self::harmonise($address->getFirstname(), 'alphanumeric', 35);
                 $res .= self::harmonise($address->getAddress2(), 'alphanumeric', 35);
                 // Invoice address info
                 $res .= self::harmonise($address->getAddress3(), 'alphanumeric', 35);
                 $res .= self::harmonise("", 'alphanumeric', 35);
                 $res .= self::harmonise("", 'alphanumeric', 35);
                 $res .= self::harmonise($address->getZipcode(), 'alphanumeric', 10);
                 // Invoice address
                 $res .= self::harmonise($address->getCity(), 'alphanumeric', 35);
                 $res .= self::harmonise("", 'alphanumeric', 10);
                 $res .= self::harmonise($address->getAddress1(), 'alphanumeric', 35);
                 $res .= self::harmonise("", 'alphanumeric', 10);
                 $res .= self::harmonise("F", 'alphanumeric', 3);
                 // Default invoice country code
                 $res .= self::harmonise($address->getPhone(), 'alphanumeric', 30);
                 // Invoice phone
                 $res .= self::harmonise("", 'alphanumeric', 15);
                 $res .= self::harmonise($exp_name, 'alphanumeric', 35);
                 // Expeditor name
                 $res .= self::harmonise($exp_address2, 'alphanumeric', 35);
                 // Expeditor address
                 $res .= self::harmonise("", 'alphanumeric', 140);
                 $res .= self::harmonise($exp_zipcode, 'alphanumeric', 10);
                 $res .= self::harmonise($exp_city, 'alphanumeric', 35);
                 $res .= self::harmonise("", 'alphanumeric', 10);
                 $res .= self::harmonise($exp_address1, 'alphanumeric', 35);
                 $res .= self::harmonise("", 'alphanumeric', 10);
                 $res .= self::harmonise("F", 'alphanumeric', 3);
                 // Default expeditor country code
                 $res .= self::harmonise($exp_phone, 'alphanumeric', 30);
                 // Expeditor phone
                 $res .= self::harmonise("", 'alphanumeric', 35);
                 // Order comment 1
                 $res .= self::harmonise("", 'alphanumeric', 35);
                 // Order comment 2
                 $res .= self::harmonise("", 'alphanumeric', 35);
                 // Order comment 3
                 $res .= self::harmonise("", 'alphanumeric', 35);
                 // Order comment 4
                 $res .= self::harmonise($date_format . ' ', 'alphanumeric', 10);
                 // Date
                 $res .= self::harmonise($exp_code, 'numeric', 8);
                 // Expeditor DPD code
                 $res .= self::harmonise("", 'alphanumeric', 35);
                 // Bar code
                 $res .= self::harmonise($customer->getRef(), 'alphanumeric', 35);
                 // Customer ref
                 $res .= self::harmonise("", 'alphanumeric', 29);
                 $res .= self::harmonise($assur_price, 'float', 9);
                 // Insured value
                 $res .= self::harmonise("", 'alphanumeric', 8);
                 $res .= self::harmonise($customer->getId(), 'alphanumeric', 35);
                 // Customer ID
                 $res .= self::harmonise("", 'alphanumeric', 46);
                 $res .= self::harmonise($exp_email, 'alphanumeric', 80);
                 // Expeditor email
                 $res .= self::harmonise($exp_cellphone, 'alphanumeric', 35);
                 // Expeditor cellphone
                 $res .= self::harmonise($customer->getEmail(), 'alphanumeric', 80);
                 // Customer email
                 $res .= self::harmonise($cellphone, 'alphanumeric', 35);
                 // Invoice cellphone
                 $res .= self::harmonise("", 'alphanumeric', 96);
                 $res .= self::harmonise($icirelais_code->getCode(), 'alphanumeric', 8);
                 // DPD relay ID
                 $res .= "\r\n";
             }
         }
     }
     $response = new Response(utf8_decode(mb_strtoupper($res)), 200, array('Content-Type' => 'application/csv-tab-delimited-table;charset=iso-8859-1', 'Content-disposition' => 'filename=export.dat'));
     return $response;
 }
 public function buildModelCriteria()
 {
     return OrderQuery::create()->filterByDeliveryModuleId(DpdPickup::getModuleId())->filterByStatusId([DpdPickup::STATUS_PAID, DpdPickup::STATUS_PROCESSING])->orderByCreatedAt(Criteria::DESC);
 }