$sql .= ", '" . $object->element . "'";
     $sql .= ")";
     if ($db->query($sql)) {
         $db->commit();
     } else {
         $db->rollback();
     }
 }
 while ($ii < $nn) {
     include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
     $objectsrc = new Commande($db);
     dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
     $result = $objectsrc->fetch($orders_id[$ii]);
     if ($result > 0) {
         if ($closeOrders) {
             $objectsrc->classifyBilled();
             $objectsrc->setStatut(3);
         }
         $lines = $objectsrc->lines;
         if (empty($lines) && method_exists($objectsrc, 'fetch_lines')) {
             $objectsrc->fetch_lines();
             $lines = $objectsrc->lines;
         }
         $fk_parent_line = 0;
         $num = count($lines);
         for ($i = 0; $i < $num; $i++) {
             $desc = $lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle;
             if ($lines[$i]->subprice < 0) {
                 // Negative line, we create a discount line
                 $discount = new DiscountAbsolute($db);
                 $discount->fk_soc = $object->socid;
Exemple #2
0
/**
 * Update an order
 *
 * @param	array		$authentication		Array of authentication information
 * @param	array		$order				Order info
 * @return	array							Array result
 */
function updateOrder($authentication, $order)
{
    global $db, $conf, $langs;
    $now = dol_now();
    dol_syslog("Function: updateOrder login="******"Order id or ref or ref_ext is mandatory.";
    }
    if (!$error) {
        $objectfound = false;
        include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
        $object = new Commande($db);
        $result = $object->fetch($order['id'], empty($order['id']) ? $order['ref'] : '', empty($order['id']) && empty($order['ref']) ? $order['ref_ext'] : '');
        if (!empty($object->id)) {
            $objectfound = true;
            $db->begin();
            if (isset($order['status'])) {
                if ($order['status'] == -1) {
                    $result = $object->cancel($fuser);
                }
                if ($order['status'] == 1) {
                    $result = $object->valid($fuser);
                }
                if ($order['status'] == 0) {
                    $result = $object->set_reopen($fuser);
                }
                if ($order['status'] == 3) {
                    $result = $object->cloture($fuser);
                }
            }
            if (isset($order['billed'])) {
                if ($order['billed']) {
                    $result = $object->classifyBilled($fuser);
                }
                if (!$order['billed']) {
                    $result = $object->classifyBilled($fuser);
                }
            }
            //Retreive all extrafield for object
            // fetch optionals attributes and labels
            $extrafields = new ExtraFields($db);
            $extralabels = $extrafields->fetch_name_optionals_label('commande', true);
            foreach ($extrafields->attribute_label as $key => $label) {
                $key = 'options_' . $key;
                if (isset($order[$key])) {
                    $result = $object->setValueFrom($key, $order[$key], 'commande_extrafields');
                }
            }
            if ($result <= 0) {
                $error++;
            }
        }
        if (!$error && $objectfound) {
            $db->commit();
            $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $object->id);
        } elseif ($objectfound) {
            $db->rollback();
            $error++;
            $errorcode = 'KO';
            $errorlabel = $object->error;
        } else {
            $error++;
            $errorcode = 'NOT_FOUND';
            $errorlabel = 'Order id=' . $order['id'] . ' ref=' . $order['ref'] . ' ref_ext=' . $order['ref_ext'] . ' cannot be found';
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}