Beispiel #1
0
 /**
  * testContratCreate
  *
  * @return	int
  */
 public function testContratCreate()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $localobject = new Contrat($this->savdb);
     $localobject->initAsSpecimen();
     $result = $localobject->create($user);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     return $result;
 }
Beispiel #2
0
    $object->fk_project     = trim($_POST["projectid"]);
    $object->remise_percent = trim($_POST["remise_percent"]);
    $object->ref            = trim($_POST["ref"]);

    // Check
    if (empty($datecontrat))
    {
        $error++;
        $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'</div>';
        $_GET["socid"]=$_POST["socid"];
        $action='create';
    }

    if (! $error)
    {
        $result = $object->create($user,$langs,$conf);
        if ($result > 0)
        {
            Header("Location: fiche.php?id=".$object->id);
            exit;
        }
        else {
            $mesg='<div class="error">'.$object->error.'</div>';
        }
        $_GET["socid"]=$_POST["socid"];
        $action='create';
    }
}

if ($action == 'classin')
{
if (GETPOST("action") == 'add') {
    $datect = @dol_mktime($_POST["datecthour"], $_POST["datectmin"], $_POST["datectsec"], $_POST["datectmonth"], $_POST["datectday"], $_POST["datectyear"]);
    $contrat = new Contrat($db);
    $contrat->local_id = GETPOST("local_id");
    $contrat->locataire_id = GETPOST("locataire_id");
    $contrat->date_entree = $datect;
    $contrat->montant_tot = GETPOST("montant_tot");
    $contrat->loy = GETPOST("loy");
    $contrat->charges = GETPOST("charges");
    $contrat->tva = GETPOST("tva");
    $contrat->periode = GETPOST("periode");
    $contrat->depot = GETPOST("depot");
    $contrat->commentaire = GETPOST("commentaire");
    $contrat->proprietaire_id = GETPOST("proprietaire_id");
    $e_contrat = $contrat;
    $res = $contrat->create($user);
    if ($res == 0) {
    } else {
        if ($res == -3) {
            $_error = 1;
            $action = "create";
        }
        if ($res == -4) {
            $_error = 2;
            $action = "create";
        }
    }
    Header("Location: " . DOL_URL_ROOT . "/immobilier/contrat.php");
} elseif (GETPOST("action") == 'maj') {
    $error = 0;
    $datect = dol_mktime(0, 0, 0, GETPOST('datectmonth', 'int'), GETPOST('datectday', 'int'), GETPOST('datectyear', 'int'));
 // For compatibility
 if ($element == 'order') {
     $element = $subelement = 'commande';
 }
 if ($element == 'propal') {
     $element = 'comm/propal';
     $subelement = 'propal';
 }
 $object->origin = $_POST['origin'];
 $object->origin_id = $_POST['originid'];
 // Possibility to add external linked objects with hooks
 $object->linked_objects[$object->origin] = $object->origin_id;
 if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
     $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
 }
 $id = $object->create($user);
 if ($id < 0) {
     setEventMessage($object->error, 'errors');
 }
 if ($id > 0) {
     dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
     $classname = ucfirst($subelement);
     $srcobject = new $classname($db);
     dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
     $result = $srcobject->fetch($object->origin_id);
     if ($result > 0) {
         $srcobject->fetch_thirdparty();
         $lines = $srcobject->lines;
         if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
             $srcobject->fetch_lines();
             $lines = $srcobject->lines;