Work on invoice creation when creating subscriptions

This commit is contained in:
Laurent Destailleur
2010-09-07 00:38:03 +00:00
parent 3b5d63440a
commit 110e66db18
3 changed files with 96 additions and 75 deletions

View File

@@ -174,6 +174,7 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
} }
} }
$invoice->socid=$adh->fk_soc; $invoice->socid=$adh->fk_soc;
$invoice->date=$datecotisation;
$result=$invoice->create($user); $result=$invoice->create($user);
if ($result <= 0) if ($result <= 0)
@@ -191,6 +192,16 @@ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisatio
{ {
$errmsg=$invoice->error; $errmsg=$invoice->error;
$error++; $error++;
}
$result=$invoice->validate($user);
if ($option == 'bankviainvoice')
{
// Now we add payment
// TODO
} }
} }
} }
@@ -280,6 +291,27 @@ if ($rowid)
// Status // Status
print '<tr><td>'.$langs->trans("Status").'</td><td class="valeur">'.$adh->getLibStatut(4).'</td></tr>'; print '<tr><td>'.$langs->trans("Status").'</td><td class="valeur">'.$adh->getLibStatut(4).'</td></tr>';
// Date end subscription
// Date fin cotisation
print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
if ($adh->datefin)
{
if ($adh->datefin < time())
{
print dol_print_date($adh->datefin,'day');
if ($adh->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
}
else
{
print dol_print_date($adh->datefin,'day');
}
}
else
{
print $langs->trans("SubscriptionNotReceived");
if ($adh->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
}
print '</td></tr>';
print "</table>\n"; print "</table>\n";
print '</form>'; print '</form>';
@@ -302,49 +334,22 @@ if ($rowid)
* Barre d'actions * Barre d'actions
*/ */
print '<div class="tabsAction">';
// Lien nouvelle cotisation si non brouillon et non resilie // Lien nouvelle cotisation si non brouillon et non resilie
if ($user->rights->adherent->cotisation->creer) if ($user->rights->adherent->cotisation->creer)
{ {
if ($action != 'addsubscription') if ($action != 'addsubscription')
{ {
print '<div class="tabsAction">';
if ($adh->statut > 0) print "<a class=\"butAction\" href=\"card_subscriptions.php?rowid=$rowid&action=addsubscription\">".$langs->trans("AddSubscription")."</a>"; if ($adh->statut > 0) print "<a class=\"butAction\" href=\"card_subscriptions.php?rowid=$rowid&action=addsubscription\">".$langs->trans("AddSubscription")."</a>";
else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a>'; else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a>';
print "<br>\n"; print "<br>\n";
}
}
print '</div>'; print '</div>';
// Date fin cotisation
print "<table class=\"border\" width=\"50%\">\n";
print '<tr><td>'.$langs->trans("SubscriptionEndDate");
print '</td>';
print '<td>';
if ($adh->datefin)
{
if ($adh->datefin < time())
{
print dol_print_date($adh->datefin,'day');
if ($adh->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
}
else
{
print dol_print_date($adh->datefin,'day');
}
}
else
{
print $langs->trans("SubscriptionNotReceived");
if ($adh->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
}
print '</td>';
print '</tr>';
print '</table>';
print '<br>'; print '<br>';
}
}
/* /*

View File

@@ -1188,7 +1188,7 @@ class Adherent extends CommonObject
$result=$adh->add_to_mailman($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT); $result=$adh->add_to_mailman($conf->global->ADHERENT_MAILMAN_LISTS_COTISANT);
} }
// Insertion dans la gestion bancaire si configure pour // Insert into bank account directlty (if option choosed for)
if ($option == 'bankdirect' && $accountid) if ($option == 'bankdirect' && $accountid)
{ {
$acct=new Account($this->db); $acct=new Account($this->db);

View File

@@ -2411,17 +2411,17 @@ function price($amount, $html=0, $outlangs='', $trunc=1, $rounding=-1)
} }
/** /**
* \brief Function that return a number with universal decimal format (decimal separator is '.') from * Function that return a number with universal decimal format (decimal separator is '.') from
* an amount typed by a user. * an amount typed by a user.
* \remarks Function to use on each input amount before any numeric test or database insert. * Function to use on each input amount before any numeric test or database insert.
* \param amount Amount to convert/clean * @param amount Amount to convert/clean
* \param rounding ''=No rounding * @param rounding ''=No rounding
* 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT) * 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT)
* 'MT'=Round to Max for totals with Tax (MAIN_MAX_DECIMALS_TOT) * 'MT'=Round to Max for totals with Tax (MAIN_MAX_DECIMALS_TOT)
* 'MS'=Round to Max Shown (MAIN_MAX_DECIMALS_SHOWN) * 'MS'=Round to Max Shown (MAIN_MAX_DECIMALS_SHOWN)
* \param alreadysqlnb Put 1 if you know that content is already universal format number * @param alreadysqlnb Put 1 if you know that content is already universal format number
* \return string Amount with universal numeric format (Example: '99.99999') * @return string Amount with universal numeric format (Example: '99.99999')
* \seealso price Opposite function of price2num * @see price Opposite function of price2num
*/ */
function price2num($amount,$rounding='',$alreadysqlnb=0) function price2num($amount,$rounding='',$alreadysqlnb=0)
{ {
@@ -2497,10 +2497,11 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
} }
/** /**
* \brief Return localtaxe rate for a particular tva * Return localtaxe rate for a particular tva
* \param tva Vat taxe * @param tva Vat taxe
* \param local Local taxe to search and return * @param local Local taxe to search and return
* \return int 0 if not found, localtax if found * @param societe_acheteuse Object of buying third party
* @return int 0 if not found, localtax if found
*/ */
function get_localtax($tva, $local, $societe_acheteuse="") function get_localtax($tva, $local, $societe_acheteuse="")
{ {
@@ -2534,7 +2535,11 @@ function get_localtax($tva, $local, $societe_acheteuse="")
} }
/** /**
* Return vat rate of a product in a particular selling country. * Return vat rate of a product in a particular selling country or default country
* vat if product is unknown.
* @param idprod Id of product or 0 if not a predefined product
* @param countrycode Country code (FR, US, IT, ...)
* @return int <0 if KO, Vat rate if OK
* TODO May be this should be better as a method of product class * TODO May be this should be better as a method of product class
*/ */
function get_product_vat_for_country($idprod, $countrycode) function get_product_vat_for_country($idprod, $countrycode)
@@ -2542,20 +2547,29 @@ function get_product_vat_for_country($idprod, $countrycode)
global $db,$mysoc; global $db,$mysoc;
$ret=0; $ret=0;
$found=0;
if ($idprod > 0)
{
// Load product // Load product
$product=new Product($db); $product=new Product($db);
$product->fetch($idprod); $result=$product->fetch($idprod);
if ($mysoc->pays_code == $countrycode) // If selling country is ours if ($mysoc->pays_code == $countrycode) // If selling country is ours
{ {
$ret=$product->tva_tx; // Default vat of product we defined $ret=$product->tva_tx; // Default vat of product we defined
$found=1;
} }
else else
{ {
// TODO Read default product vat according to countrycode // TODO Read default product vat according to countrycode and product
}
}
if (! $found)
{
// If vat of product for the country not found or not defined, we return higher vat of country. // If vat of product for the country not found or not defined, we return higher vat of country.
$sql.="SELECT taux as vat_rate"; $sql.="SELECT taux as vat_rate";
$sql.=" FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p"; $sql.=" FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
@@ -2575,12 +2589,16 @@ function get_product_vat_for_country($idprod, $countrycode)
else dol_print_error($db); else dol_print_error($db);
} }
//print "ret=".$ret;exit; dol_syslog("get_product_vat_for_country: ret=".$ret);
return $ret; return $ret;
} }
/** /**
* Return localtax rate of a product in a particular selling country * Return localtax rate of a product in a particular selling country
* @param idprod Id of product
* @package local 1 for localtax1, 2 for localtax 2
* @param countrycode Country code (FR, US, IT, ...)
* @return int <0 if KO, Vat rate if OK
* TODO May be this should be better as a method of product class * TODO May be this should be better as a method of product class
*/ */
function get_product_localtax_for_country($idprod, $local, $countrycode) function get_product_localtax_for_country($idprod, $local, $countrycode)
@@ -2597,17 +2615,17 @@ function get_product_localtax_for_country($idprod, $local, $countrycode)
} }
/** /**
* \brief Function that return vat rate of a product line (according to seller, buyer and product vat rate) * Function that return vat rate of a product line (according to seller, buyer and product vat rate)
* \remarks Si vendeur non assujeti a TVA, TVA par defaut=0. Fin de regle. * Si vendeur non assujeti a TVA, TVA par defaut=0. Fin de regle.
* Si le (pays vendeur = pays acheteur) alors TVA par defaut=TVA du produit vendu. Fin de regle. * Si le (pays vendeur = pays acheteur) alors TVA par defaut=TVA du produit vendu. Fin de regle.
* Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par acheteur au centre d'impots de son pays et non au vendeur). Fin de regle. * Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
* Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = particulier ou entreprise sans num TVA intra) alors TVA par defaut=TVA du produit vendu. Fin de regle * Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = particulier ou entreprise sans num TVA intra) alors TVA par defaut=TVA du produit vendu. Fin de regle
* Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = entreprise avec num TVA) intra alors TVA par defaut=0. Fin de regle * Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = entreprise avec num TVA) intra alors TVA par defaut=0. Fin de regle
* Sinon TVA proposee par defaut=0. Fin de regle. * Sinon TVA proposee par defaut=0. Fin de regle.
* \param societe_vendeuse Objet societe vendeuse * @param societe_vendeuse Objet societe vendeuse
* \param societe_acheteuse Objet societe acheteuse * @param societe_acheteuse Objet societe acheteuse
* \param idprod Id product * @param idprod Id product
* \return float Taux de tva a appliquer, -1 si ne peut etre determine * @return float Taux de tva a appliquer, -1 si ne peut etre determine
*/ */
function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0) function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0)
{ {
@@ -2616,7 +2634,7 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0)
if (!is_object($societe_vendeuse)) return -1; if (!is_object($societe_vendeuse)) return -1;
if (!is_object($societe_acheteuse)) return -1; if (!is_object($societe_acheteuse)) return -1;
dol_syslog("get_default_tva seller use vat=".$societe_vendeuse->tva_assuj." seller country=".$societe_vendeuse->pays_code.", seller in cee=".$societe_vendeuse->isInEEC().", buyer country=".$societe_acheteuse->pays_code.", buyer in cee=".$societe_acheteuse->isInEEC().", idprod=".$idprod); dol_syslog("get_default_tva: seller use vat=".$societe_vendeuse->tva_assuj.", seller country=".$societe_vendeuse->pays_code.", seller in cee=".$societe_vendeuse->isInEEC().", buyer country=".$societe_acheteuse->pays_code.", buyer in cee=".$societe_acheteuse->isInEEC().", idprod=".$idprod);
// Si vendeur non assujeti a TVA (tva_assuj vaut 0/1 ou franchise/reel) // Si vendeur non assujeti a TVA (tva_assuj vaut 0/1 ou franchise/reel)
if (is_numeric($societe_vendeuse->tva_assuj) && ! $societe_vendeuse->tva_assuj) return 0; if (is_numeric($societe_vendeuse->tva_assuj) && ! $societe_vendeuse->tva_assuj) return 0;
@@ -2627,8 +2645,7 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0)
// Le test ci-dessus ne devrait pas etre necessaire. Me signaler l'exemple du cas juridique concerne si le test suivant n'est pas suffisant. // Le test ci-dessus ne devrait pas etre necessaire. Me signaler l'exemple du cas juridique concerne si le test suivant n'est pas suffisant.
if ($societe_vendeuse->pays_code == $societe_acheteuse->pays_code) // Warning ->pays_id not always defined if ($societe_vendeuse->pays_code == $societe_acheteuse->pays_code) // Warning ->pays_id not always defined
{ {
if ($idprod) return get_product_vat_for_country($idprod,$societe_vendeuse->pays_code); return get_product_vat_for_country($idprod,$societe_vendeuse->pays_code);
return -1; // Si produit absent, on ne peut determiner taux tva
} }
// Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle. // Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
@@ -2645,8 +2662,7 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0)
} }
else else
{ {
if ($idprod) return get_product_vat_for_country($idprod,$societe_vendeuse->pays_code); return get_product_vat_for_country($idprod,$societe_vendeuse->pays_code);
return -1; // Si produit absent, on ne peut determiner taux tva
} }
} }