示例#1
0
        $object->setDocModel($user, $_REQUEST['model']);
    }
    // Define output language
    $outputlangs = $langs;
    $newlang = '';
    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
        $newlang = $_REQUEST['lang_id'];
    }
    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
        $newlang = $object->client->default_lang;
    }
    if (!empty($newlang)) {
        $outputlangs = new Translate("", $conf);
        $outputlangs->setDefaultLang($newlang);
    }
    $result = commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
    if ($result <= 0) {
        dol_print_error($db, $result);
        exit;
    } else {
        Header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc'));
        exit;
    }
}
// Remove file in doc form
if ($action == 'remove_file') {
    if ($object->fetch($id)) {
        require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php";
        $upload_dir = $conf->commande->dir_output;
        $file = $upload_dir . '/' . $_GET['file'];
        dol_delete_file($file);
 /**
  * @param   array         $parameters     Hook metadatas (context, etc...)
  * @param   Commande    $object        The object to process
  * @param   string          $action        Current action (if set). Generally create or edit or null
  * @param   HookManager     $hookmanager    Hook manager propagated to allow calling another hook
  * @return  int                             < 0 on error, 0 on success, 1 to replace standard code
  */
 public function formConfirm(array $parameters, Commande $object, &$action, HookManager $hookmanager)
 {
     global $langs, $db, $conf;
     $langs->load('importorderlines@importorderlines');
     if ($object->statut >= 1) {
         return 0;
     }
     require __DIR__ . '/Utils.php';
     if ($action == 'import') {
         $this->resprints = Utils::uploadForm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ImportOrderLines'), $langs->trans('ConfirmCloneOrder', $object->ref), 'confirm_import', $langs->trans('SelectFileToImport'));
     } elseif ($action == 'confirm_import') {
         try {
             if (!isset($_FILES['uploadfile'])) {
                 throw new Exception($langs->trans('UploadFileError'));
             }
             $file = $_FILES['uploadfile'];
             if (!is_uploaded_file($file['tmp_name'])) {
                 throw new Exception($langs->trans('UploadFileError'));
             }
             if ($file['error'] != UPLOAD_ERR_OK) {
                 throw new Exception($langs->trans('UploadFileError'), $file['error']);
             }
             require __DIR__ . '/../lib/phpoffice/phpexcel/Classes/PHPExcel.php';
             //Supported PHPExcel File readers to ensure we deal with a Spreadsheet.
             $supported_filereaders = array('CSV', 'Excel2007', 'Excel5', 'OOCalc', 'Excel2003XML');
             if (!in_array(PHPExcel_IOFactory::identify($file['tmp_name']), $supported_filereaders)) {
                 throw new Exception($langs->trans('UploadFileErrorUnsupportedFormat'));
             }
             try {
                 $excelfd = PHPExcel_IOFactory::load($file['tmp_name']);
             } catch (PHPExcel_Reader_Exception $e) {
                 throw new Exception($e->getMessage());
             }
             $activesheet = $excelfd->getActiveSheet();
             //Check of the format
             $a1 = $activesheet->getCell('A1')->getValue() == $langs->transnoentities('Ref');
             $b1 = $activesheet->getCell('B1')->getValue() == $langs->transnoentities('Label');
             $c1 = $activesheet->getCell('C1')->getValue() == $langs->transnoentities('Qty');
             if (!$a1 || !$b1 || !$c1) {
                 throw new Exception($langs->trans('UploadFileErrorFormat'));
             }
             $maxrow = $activesheet->getHighestRow();
             for ($i = 2; $i <= $maxrow; $i++) {
                 $qty = (int) $activesheet->getCellByColumnAndRow(2, $i)->getValue();
                 if ($qty > 0) {
                     $ref = $activesheet->getCellByColumnAndRow(0, $i)->getValue();
                     $prod = new Product($db);
                     if ($prod->fetch('', $ref) <= 0) {
                         throw new Exception($langs->trans('ErrorProductNotFound', $ref));
                     }
                     Utils::addOrderLine($object, $prod, $qty);
                     unset($prod);
                 }
             }
         } catch (Exception $e) {
             $message = $e->getMessage();
             setEventMessage($e->getMessage(), 'errors');
             if ($e->getCode()) {
                 $message .= '. Error code: ' . $e->getCode();
             }
             dol_syslog('[importorderlines] ' . $message, LOG_DEBUG);
             return -1;
         }
         //Delete temporary file
         unlink($file['tmp_name']);
         //Reload the object with new lines
         $object->fetch($object->id);
         if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
             // Define output language
             $outputlangs = $langs;
             $newlang = GETPOST('lang_id', 'alpha');
             if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
                 $newlang = $object->thirdparty->default_lang;
             }
             if (!empty($newlang)) {
                 $outputlangs = new Translate("", $conf);
                 $outputlangs->setDefaultLang($newlang);
             }
             // PDF
             $hidedetails = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
             $hidedesc = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
             $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
             commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
         }
     }
     return 0;
 }
示例#3
0
    /**
     * testCommandeBuild
     *
     * @return int
     */
    public function testCommandeBuild()
    {
        global $conf,$user,$langs,$db;
        $conf=$this->savconf;
        $user=$this->savuser;
        $langs=$this->savlangs;
        $db=$this->savdb;

        $conf->commande->dir_output.='/temp';
        $localobject=new Commande($this->savdb);
        $localobject->initAsSpecimen();

        // Einstein
        $localobject->modelpdf='einstein';
        $result=commande_pdf_create($db, $localobject, $localobject->modelpdf, $langs);

        $this->assertLessThan($result, 0);
        print __METHOD__." result=".$result."\n";

        // Edison
        $localobject->modelpdf='edison';
        $result=commande_pdf_create($db, $localobject, $localobject->modelpdf, $langs);

        $this->assertLessThan($result, 0);
        print __METHOD__." result=".$result."\n";

        return 0;
    }
 // Build document if it not exists
 if (!$file || !is_readable($file)) {
     // Define output language
     $outputlangs = $langs;
     $newlang = '';
     if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
         $newlang = $_REQUEST['lang_id'];
     }
     if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
         $newlang = $object->client->default_lang;
     }
     if (!empty($newlang)) {
         $outputlangs = new Translate("", $conf);
         $outputlangs->setDefaultLang($newlang);
     }
     $result = commande_pdf_create($db, $object, GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
     if ($result <= 0) {
         dol_print_error($db, $result);
         exit;
     }
     $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/'));
     $file = $fileparams['fullname'];
 }
 print '<br>';
 print_titre($langs->trans('SendOrderByMail'));
 // Cree l'objet formulaire mail
 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
 $formmail = new FormMail($db);
 $formmail->fromtype = 'user';
 $formmail->fromid = $user->id;
 $formmail->fromname = $user->getFullName($langs);
/**
 * Valid an order
 *
 * @param	array		$authentication		Array of authentication information
 * @param	int			$id					Id of order to validate
 * @return	array							Array result
 */
function validOrder($authentication, $id = '')
{
    global $db, $conf, $langs;
    dol_syslog("Function: validOrder login="******" id=" . $id . " ref=" . $ref . " ref_ext=" . $ref_ext);
    // Init and check authentication
    $objectresp = array();
    $errorcode = '';
    $errorlabel = '';
    $error = 0;
    if ($authentication['entity']) {
        $conf->entity = $authentication['entity'];
    }
    $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
    if (!$error) {
        $fuser->getrights();
        if ($fuser->rights->commande->lire) {
            $order = new Commande($db);
            $result = $order->fetch($id, $ref, $ref_ext);
            $order->fetch_thirdparty();
            $db->begin();
            if ($result > 0) {
                $result = $order->valid($fuser);
                if ($result >= 0) {
                    // Define output language
                    $outputlangs = $langs;
                    commande_pdf_create($db, $order, $order->modelpdf, $outputlangs, 0, 0, 0);
                } else {
                    $db->rollback();
                    $error++;
                    $errorcode = 'KO';
                    $errorlabel = $newobject->error;
                }
            } else {
                $db->rollback();
                $error++;
                $errorcode = 'KO';
                $errorlabel = $newobject->error;
            }
        } else {
            $db->rollback();
            $error++;
            $errorcode = 'KO';
            $errorlabel = $newobject->error;
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    } else {
        $db->commit();
        $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''));
    }
    return $objectresp;
}