Ejemplo n.º 1
0
 /**
  *		Load an object from its id and create a new one in database
  *		@param      fromid     		Id of object to clone
  *		@param		invertdetail	Reverse sign of amounts for lines
  * 	 	@return		int				New id of clone
  */
 function createFromClone($fromid, $invertdetail = 0)
 {
     global $conf, $user, $langs;
     $error = 0;
     // Load source object
     $objFrom = new Facture($this->db);
     $objFrom->fetch($fromid);
     // Load new object
     $object = new Facture($this->db);
     $object->fetch($fromid);
     // Instantiate hooks of thirdparty module
     if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) {
         $object->callHooks('invoicecard');
     }
     $this->db->begin();
     $object->id = 0;
     $object->statut = 0;
     // Clear fields
     $object->user_author = $user->id;
     $object->user_valid = '';
     $object->fk_facture_source = 0;
     $object->date_creation = '';
     $object->date_validation = '';
     $object->ref_client = '';
     $object->close_code = '';
     $object->close_note = '';
     $object->products = $object->lines;
     // Tant que products encore utilise
     // Loop on each line of new invoice
     foreach ($object->lines as $i => $line) {
         if (($object->lines[$i]->info_bits & 0x2) == 0x2) {
             unset($object->lines[$i]);
             unset($object->products[$i]);
             // Tant que products encore utilise
         }
     }
     // Create clone
     $result = $object->create($user);
     // Other options
     if ($result < 0) {
         $this->error = $object->error;
         $error++;
     }
     if (!$error) {
         // Hook for external modules
         if (!empty($object->hooks)) {
             foreach ($object->hooks as $hook) {
                 if (!empty($hook['modules'])) {
                     foreach ($hook['modules'] as $module) {
                         if (method_exists($module, 'createfrom')) {
                             $result = $module->createfrom($objFrom, $result, $object->element);
                             if ($result < 0) {
                                 $error++;
                             }
                         }
                     }
                 }
             }
         }
         // Appel des triggers
         include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('BILL_CLONE', $object, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // Fin appel triggers
     }
     // End
     if (!$error) {
         $this->db->commit();
         return $object->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Ejemplo n.º 2
0
// Security check
$fieldid = isset($_GET["ref"])?'facnumber':'rowid';
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);

// Nombre de ligne pour choix de produit/service predefinis
$NBLINES=4;

$usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;

$object=new Facture($db);

// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
    $object->callHooks('invoicecard');
}



/******************************************************************************/
/*                     Actions                                                */
/******************************************************************************/

// Hook of actions
if (! empty($object->hooks))
{
	foreach($object->hooks as $hook)
	{
		if (! empty($hook['modules']))
		{
Ejemplo n.º 3
0
/*
 * Create mode
 */
if ($_GET["action"] == 'create')
{
	print_fiche_titre($langs->trans("CreateRepeatableInvoice"));

	if ($mesg) print $mesg.'<br>';

	$facture = new Facture($db);   // Source invoice
	$product_static=new Product($db);

	// Instantiate hooks of thirdparty module
	if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
	{
		$facture->callHooks('invoicecard');
	}

	if ($facture->fetch($_GET["facid"]) > 0)
	{
		print '<form action="fiche-rec.php" method="post">';
		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
		print '<input type="hidden" name="action" value="add">';
		print '<input type="hidden" name="facid" value="'.$facture->id.'">';

		print '<table class="border" width="100%">';

		$facture->fetch_thirdparty();

		print '<tr><td>'.$langs->trans("Customer").'</td><td>'.$facture->client->getNomUrl(1).'</td>';
		print '<td>';