Skip to content

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed May 25, 2018
2 parents 4b10576 + 184fec4 commit 136dff6
Show file tree
Hide file tree
Showing 19 changed files with 754 additions and 697 deletions.
13 changes: 8 additions & 5 deletions generate/custom.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ function plugin_order_getCustomFieldsForODT($ID, $odttemplates_id, $odf, $signat
$odf->mergeSegment($article);
$prices = $PluginOrderOrder_Item->getAllPrices($ID);

// total price (with postage)
$postagewithTVA =
$PluginOrderOrder_Item->getPricesATI($order->fields["port_price"],
Dropdown::getDropdownName("glpi_plugin_order_ordertaxes",
$order->fields["plugin_order_ordertaxes_id"]));
// total price (with postage)
$tax = new PluginOrderOrderTax();
$tax->getFromDB($order->fields["plugin_order_ordertaxes_id"]);

$postagewithTVA = $PluginOrderOrder_Item->getPricesATI(
$order->fields["port_price"],
$tax->getRate()
);

$total_HT = $prices["priceHT"] + $order->fields["port_price"];
$total_TVA = $prices["priceTVA"] + $postagewithTVA - $order->fields["port_price"];
Expand Down
73 changes: 44 additions & 29 deletions inc/notificationtargetorder.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ public static function install(Migration $migration) {
$migration->displayMessage("Migrate PluginOrderOrder notifications");

$template = new NotificationTemplate();
$translation = new NotificationTemplateTranslation();
$notification = new Notification();
$n_n_template = new Notification_NotificationTemplate();

$templates_id = false;
$query_id = "SELECT `id`
FROM `glpi_notificationtemplates`
Expand All @@ -218,7 +222,6 @@ public static function install(Migration $migration) {
}

if ($templates_id) {
$translation = new NotificationTemplateTranslation();
if (!countElementsInTable($translation->getTable(), "`notificationtemplates_id`='$templates_id'")) {
$tmp = [];
$tmp['notificationtemplates_id'] = $templates_id;
Expand Down Expand Up @@ -257,21 +260,26 @@ public static function install(Migration $migration) {
'Cancel Order Validation' => 'undovalidation',
'Cancel Order' => 'cancel',
];
$notification = new Notification();
foreach ($notifs as $label => $name) {
if (!countElementsInTable("glpi_notifications", "`itemtype`='PluginOrderOrder' AND `event`='$name'")) {
$notification->add([
$notification_id = $notification->add([
'name' => $label,
'entities_id' => 0,
'itemtype' => 'PluginOrderOrder',
'event' => $name,
'mode' => 'mail',
'comment' => '',
'is_recursive' => 1,
'is_active' => 1,
'date_mod' => $_SESSION['glpi_currenttime'],
'notificationtemplates_id' => $templates_id,
]);

$n_n_template->add(
[
'notifications_id' => $notification_id,
'mode' => Notification_NotificationTemplate::MODE_MAIL,
'notificationtemplates_id' => $templates_id,
]
);
}
}
}
Expand All @@ -295,7 +303,6 @@ public static function install(Migration $migration) {
}

if ($templates_id) {
$translation = new NotificationTemplateTranslation();
if (!countElementsInTable($translation->getTable(), "`notificationtemplates_id`='$templates_id'")) {
$tmp = [];
$tmp['notificationtemplates_id'] = $templates_id;
Expand All @@ -321,26 +328,30 @@ public static function install(Migration $migration) {
}

$notifs = ['Due date overtaken' => 'duedate'];
$notification = new Notification();
foreach ($notifs as $label => $name) {
if (!countElementsInTable("glpi_notifications", "`itemtype`='PluginOrderOrder' AND `event`='$name'")) {
$notification->add([
$notification_id = $notification->add([
'name' => $label,
'entities_id' => 0,
'itemtype' => 'PluginOrderOrder',
'event' => $name,
'mode' => 'mail',
'comment' => '',
'is_recursive' => 1,
'is_active' => 1,
'date_mod' => $_SESSION['glpi_currenttime'],
'notificationtemplates_id' => $templates_id,
]);

$n_n_template->add(
[
'notifications_id' => $notification_id,
'mode' => Notification_NotificationTemplate::MODE_MAIL,
'notificationtemplates_id' => $templates_id,
]
);
}
}
}

$template = new NotificationTemplate();
$templates_id = false;
$query_id = "SELECT `id`
FROM `glpi_notificationtemplates`
Expand All @@ -361,7 +372,6 @@ public static function install(Migration $migration) {
}

if ($templates_id) {
$translation = new NotificationTemplateTranslation();
if (!countElementsInTable($translation->getTable(), "`notificationtemplates_id`='$templates_id'")) {
$tmp = [];
$tmp['notificationtemplates_id'] = $templates_id;
Expand All @@ -382,24 +392,29 @@ public static function install(Migration $migration) {
##lang.ordervalidation.entity## : <br /> ##ordervalidation.entity##</p>';
$translation->add($tmp);
}
}

$notifs = ['Order Delivered' => 'delivered'];
$notification = new Notification();
foreach ($notifs as $label => $name) {
if (!countElementsInTable("glpi_notifications", "`itemtype`='PluginOrderOrder' AND `event` = '$name'")) {
$notification->add([
'name' => $label,
'entities_id' => 0,
'itemtype' => 'PluginOrderOrder',
'event' => $name,
'mode' => 'mail',
'comment' => '',
'is_recursive' => 1,
'is_active' => 1,
'date_mod' => $_SESSION['glpi_currenttime'],
'notificationtemplates_id' => $templates_id,
]);
$notifs = ['Order Delivered' => 'delivered'];
foreach ($notifs as $label => $name) {
if (!countElementsInTable("glpi_notifications", "`itemtype`='PluginOrderOrder' AND `event` = '$name'")) {
$notification_id = $notification->add([
'name' => $label,
'entities_id' => 0,
'itemtype' => 'PluginOrderOrder',
'event' => $name,
'comment' => '',
'is_recursive' => 1,
'is_active' => 1,
'date_mod' => $_SESSION['glpi_currenttime'],
]);

$n_n_template->add(
[
'notifications_id' => $notification_id,
'mode' => Notification_NotificationTemplate::MODE_MAIL,
'notificationtemplates_id' => $templates_id,
]
);
}
}
}
}
Expand Down
32 changes: 23 additions & 9 deletions inc/order.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1150,8 +1150,13 @@ public function showForm ($ID, $options = []) {
echo "</tr>";

// total price (with postage)
$postagewithTVA = $PluginOrderOrder_Item->getPricesATI($this->fields["port_price"],
Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"]));
$tax = new PluginOrderOrderTax();
$tax->getFromDB($this->fields["plugin_order_ordertaxes_id"]);

$postagewithTVA = $PluginOrderOrder_Item->getPricesATI(
$this->fields["port_price"],
$tax->getRate()
);

$priceHTwithpostage = $prices["priceHT"] + $this->fields["port_price"];
echo "<tr>";
Expand Down Expand Up @@ -1665,9 +1670,13 @@ public function generateOrder($params) {
$prices = $PluginOrderOrder_Item->getAllPrices($ID);

// total price (with postage)
$postagewithTVA = $PluginOrderOrder_Item->getPricesATI($this->fields["port_price"],
Dropdown::getDropdownName("glpi_plugin_order_ordertaxes",
$this->fields["plugin_order_ordertaxes_id"]));
$tax = new PluginOrderOrderTax();
$tax->getFromDB($this->fields["plugin_order_ordertaxes_id"]);

$postagewithTVA = $PluginOrderOrder_Item->getPricesATI(
$this->fields["port_price"],
$tax->getRate()
);

$total_HT = $prices["priceHT"] + $this->fields["port_price"];
$total_TVA = $prices["priceTVA"] + $postagewithTVA - $this->fields["port_price"];
Expand Down Expand Up @@ -1793,12 +1802,17 @@ public static function showForBudget($budgets_id) {

$total = 0;
foreach ($DB->request($query_limit) as $data) {

$PluginOrderOrder_Item = new PluginOrderOrder_Item();
$prices = $PluginOrderOrder_Item->getAllPrices($data["id"]);
$postagewithTVA = $PluginOrderOrder_Item->getPricesATI($data["port_price"],
Dropdown::getDropdownName("glpi_plugin_order_ordertaxes",
$data["plugin_order_ordertaxes_id"]));

$tax = new PluginOrderOrderTax();
$tax->getFromDB($data["plugin_order_ordertaxes_id"]);

$postagewithTVA = $PluginOrderOrder_Item->getPricesATI(
$data["port_price"],
$tax->getRate()
);

//if state is cancel do not decremente total already use
if ($data['plugin_order_orderstates_id'] < 5) {
$total += $prices["priceHT"];
Expand Down
26 changes: 18 additions & 8 deletions inc/order_item.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,12 @@ public function checkIFReferenceExistsInOrder($orders_id, $ref_id) {


public function addDetails($ref_id, $itemtype, $orders_id, $quantity, $price, $discounted_price, $taxes_id) {

$order = new PluginOrderOrder();
if ($quantity > 0 && $order->getFromDB($orders_id)) {
$tax = new PluginOrderOrderTax();
$tax->getFromDB($taxes_id);

for ($i = 0; $i < $quantity; $i++) {
$input["plugin_order_orders_id"] = $orders_id;
$input["plugin_order_references_id"] = $ref_id;
Expand All @@ -264,10 +268,10 @@ public function addDetails($ref_id, $itemtype, $orders_id, $quantity, $price, $d
$input["price_taxfree"] = $price;
$input["price_discounted"] = $price - ($price * ($discounted_price / 100));
$input["states_id"] = PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED;;

$input["price_ati"] = $this->getPricesATI($input["price_discounted"],
Dropdown::getDropdownName("glpi_plugin_order_ordertaxes",
$taxes_id));
$input["price_ati"] = $this->getPricesATI(
$input["price_discounted"],
$tax->getRate()
);
$input["discount"] = $discounted_price;

$this->add($input);
Expand Down Expand Up @@ -1357,8 +1361,11 @@ public function updatePrice_taxfree($post) {
$input["price_taxfree"] = $post['price_taxfree'];
$input["price_discounted"] = $input["price_taxfree"] - ($input["price_taxfree"] * ($discount / 100));

$taxe_name = Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $plugin_order_ordertaxes_id);
$input["price_ati"] = $this->getPricesATI($input["price_discounted"], $taxe_name);
$tax = new PluginOrderOrderTax();
$tax->getFromDB($plugin_order_ordertaxes_id);

$input["price_ati"] = $this->getPricesATI($input["price_discounted"], $tax->getRate());

$this->update($input);
}

Expand All @@ -1374,8 +1381,11 @@ public function updateDiscount($post) {
$input["discount"] = $post['discount'];
$input["price_discounted"] = $post['price'] - ($post['price'] * ($input['discount'] / 100));

$taxe_name = Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $plugin_order_ordertaxes_id);
$input["price_ati"] = $this->getPricesATI($input["price_discounted"], $taxe_name);
$tax = new PluginOrderOrderTax();
$tax->getFromDB($plugin_order_ordertaxes_id);

$input["price_ati"] = $this->getPricesATI($input["price_discounted"], $tax->getRate());

$this->update($input);
}

Expand Down
2 changes: 1 addition & 1 deletion inc/orderinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct() {
*
* @return string (table name)
**/
static function getTable() {
static function getTable($classname = null) {

$parenttype = get_parent_class();
return $parenttype::getTable();
Expand Down
12 changes: 12 additions & 0 deletions inc/ordertax.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,17 @@ public static function uninstall() {
$DB->query("DROP TABLE IF EXISTS `".self::getTable()."`") or die ($DB->error());
}

/**
* Get the tax rate of loaded item.
*
* @return number
*/
public function getRate() {

if (array_key_exists('name', $this->fields) && !empty($this->fields['name'])) {
return floatval($this->fields['name']);
}

return 0;
}
}
2 changes: 1 addition & 1 deletion inc/referenceinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct() {
*
* @return string (table name)
**/
static function getTable() {
static function getTable($classname = null) {

$parenttype = get_parent_class();
return $parenttype::getTable();
Expand Down
Binary file modified locales/cs_CZ.mo
Binary file not shown.
Loading

0 comments on commit 136dff6

Please sign in to comment.