protected function buildForm() { // Add value(s) if Config/sender.json exists if (is_readable(ExportExaprintController::getJSONpath())) { $values = json_decode(file_get_contents(ExportExaprintController::getJSONpath()), true); } $this->formBuilder->add('name', 'text', array('label' => Translator::getInstance()->trans('Sender\'s name', [], DpdClassic::DOMAIN_NAME), 'data' => isset($values['name']) ? $values['name'] : "", 'constraints' => array(new NotBlank()), 'label_attr' => array('for' => 'name')))->add('addr', 'text', array('label' => Translator::getInstance()->trans('Sender\'s address1', [], DpdClassic::DOMAIN_NAME), 'data' => isset($values['addr']) ? $values['addr'] : "", 'constraints' => array(new NotBlank()), 'label_attr' => array('for' => 'addr')))->add('addr2', 'text', array('label' => Translator::getInstance()->trans('Sender\'s address2', [], DpdClassic::DOMAIN_NAME), 'data' => isset($values['addr2']) ? $values['addr2'] : "", 'label_attr' => array('for' => 'addr2')))->add('zipcode', 'text', array('label' => Translator::getInstance()->trans('Sender\'s zipcode', [], DpdClassic::DOMAIN_NAME), 'data' => isset($values['zipcode']) ? $values['zipcode'] : "", 'constraints' => array(new NotBlank(), new Regex(['pattern' => "/^(2[A-B])|([0-9]{2})\\d{3}\$/"])), 'label_attr' => array('for' => 'zipcode')))->add('city', 'text', array('label' => Translator::getInstance()->trans('Sender\'s city', [], DpdClassic::DOMAIN_NAME), 'data' => isset($values['city']) ? $values['city'] : "", 'constraints' => array(new NotBlank()), 'label_attr' => array('for' => 'city')))->add('tel', 'text', array('label' => Translator::getInstance()->trans('Sender\'s phone', [], DpdClassic::DOMAIN_NAME), 'data' => isset($values['tel']) ? $values['tel'] : "", 'constraints' => array(new NotBlank(), new Regex(['pattern' => "/^0[1-9]\\d{8}\$/"])), 'label_attr' => array('for' => 'tel')))->add('mobile', 'text', array('label' => Translator::getInstance()->trans('Sender\'s mobile phone', [], DpdClassic::DOMAIN_NAME), 'data' => isset($values['mobile']) ? $values['mobile'] : "", 'constraints' => array(new NotBlank(), new Regex(['pattern' => "#^0[6-7]{1}\\d{8}\$#"])), 'label_attr' => array('for' => 'mobile')))->add('mail', 'email', array('label' => Translator::getInstance()->trans('Sender\'s email', [], DpdClassic::DOMAIN_NAME), 'data' => isset($values['mail']) ? $values['mail'] : "", 'constraints' => array(new NotBlank()), 'label_attr' => array('for' => 'mail')))->add('expcode', 'text', array('label' => Translator::getInstance()->trans('DpdClassic Sender\'s code', [], DpdClassic::DOMAIN_NAME), 'constraints' => array(new NotBlank(), new Regex(['pattern' => "#^\\d{8}\$#"])), 'data' => isset($values['expcode']) ? $values['expcode'] : "", 'label_attr' => array('for' => 'expcode'))); }
public function buildArray() { $path = ExportExaprintController::getJSONpath(); if (is_readable($path) && ($order = OrderQuery::create()->findOneByRef($this->getRef())) !== null && $order->getDeliveryModuleId() === DpdClassic::getModuleId()) { $json = json_decode(file_get_contents($path), true); return array($this->getRef() => $json['expcode']); } else { return array(); } }
public function exportFileAction() { if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('DpdClassic'), AccessManager::UPDATE))) { return $response; } if (is_readable(ExportExaprintController::getJSONpath())) { $admici = json_decode(file_get_contents(ExportExaprintController::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 DpdClassic/Config/sender.json is not valid. Please correct it.", [], DpdClassic::DOMAIN_NAME), 500); } } else { return Response::create(Translator::getInstance()->trans("Can't read DpdClassic/Config/sender.json. Did you save the export information ?", [], DpdClassic::DOMAIN_NAME), 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(DpdClassic::getModuleId())->find(); // FORM VALIDATION $form = new ExportForm($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 dpdclassic.export sent with bad infos. "); return Response::create(Translator::getInstance()->trans("Got invalid data : %err", ['%err' => $e->getMessage()], DpdClassic::DOMAIN_NAME), 500); } // For each selected order /** @var Order $order */ foreach ($orders as $order) { $orderRef = str_replace(".", "-", $order->getRef()); if ($vform->get($orderRef)->getData()) { // Get if the package is assured, how many packages there are & their weight $assur_package = $vform->get($orderRef . "-assur")->getData(); $pkgNumber = $vform->get($orderRef . '-pkgNumber')->getData(); $pkgWeight = $vform->get($orderRef . '-pkgWeight')->getData(); // 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 customer's delivery address $address = OrderAddressQuery::create()->findPK($order->getDeliveryOrderAddressId()); //Get Customer object $customer = CustomerQuery::create()->findPK($order->getCustomerId()); // Get cellphone if (null == ($cellphone = $address->getCellphone())) { $address->getPhone(); } //Weight & price calc $price = 0; $price = $order->getTotalAmount($price, false); // tax = 0 && include postage = false $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); // Delivered customer $res .= self::harmonise($address->getFirstname(), 'alphanumeric', 35); $res .= self::harmonise($address->getAddress2(), 'alphanumeric', 35); // Delivered 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); // Delivered 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 delivered country code $res .= self::harmonise($address->getPhone(), 'alphanumeric', 30); // Delivered 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); // Customer phone $res .= self::harmonise("", 'alphanumeric', 96); $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; }