PreorderBilling WIP & Api changed
This commit is contained in:
@@ -929,28 +929,24 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
$prices_return = [
|
||||
"price_inet" => (float)$prices["operator_usage"]->price_inet,
|
||||
"price_inet_tv" => (float)$prices["operator_usage"]->price_inet_tv,
|
||||
"price_catv" => (float)$prices["operator_usage"]->price_catv,
|
||||
|
||||
"operator_setup_price" => (float)$prices["operator_setup"]->price_setup,
|
||||
"operator_setup_info" => $prices["operator_setup"]->description,
|
||||
"operator_setup_valid_until" => $prices["operator_setup"]->end_date,
|
||||
|
||||
"enduser_setup_price" => (float)$prices["enduser_setup"]->price_setup,
|
||||
"oaid" => $oaid,
|
||||
"enduser_setup_price_net" => (float)$prices["enduser_setup"]->price_setup,
|
||||
"enduser_setup_price_gross" => (float)$prices["enduser_setup"]->price_setup * 1.2,
|
||||
"enduser_setup_info" => $prices["enduser_setup"]->description,
|
||||
"enduser_setup_valid_until" => $prices["enduser_setup"]->end_date,
|
||||
|
||||
"vatrate" => 20,
|
||||
];
|
||||
|
||||
if(PreorderBilling::getFirst(["adb_wohneinheit_id" => $unit->id, "product_id" => $enduser_setup_product_id])) {
|
||||
$prices_return["enduser_setup_price"] = 0;
|
||||
//$paid = $unit->enduser_setup_paid;
|
||||
if(PreorderBilling::getFirst(["adb_wohneinheit_id" => $unit->id, "product_id" => $enduser_setup_product_id, "invoice_id" => false])) {
|
||||
$prices_return["enduser_setup_price_net"] = 0;
|
||||
$prices_return["enduser_setup_price_gross"] = 0;
|
||||
$prices_return["enduser_setup_info"] = "paid";
|
||||
$prices_return["enduser_setup_valid_until"] = null;
|
||||
}
|
||||
|
||||
return mfResponse::Ok(['oaid' => $oaid, 'prices' => $prices_return]);
|
||||
return mfResponse::Ok($prices_return);
|
||||
}
|
||||
|
||||
protected function exportAddresses() {
|
||||
|
||||
@@ -21,6 +21,11 @@ class Activation extends Modules\ApiControllerModule {
|
||||
if($this->me->is("Preorderreadonly")) return \mfResponse::Forbidden();
|
||||
|
||||
$code = trim($code);
|
||||
$activation_date = false;
|
||||
if(array_key_exists("activation_date", $this->get)) {
|
||||
$activation_date = trim($this->get['activation_date']);
|
||||
}
|
||||
|
||||
if(!$code) {
|
||||
return \mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
@@ -42,15 +47,42 @@ class Activation extends Modules\ApiControllerModule {
|
||||
if($preorder->partner_id != $this->me->address_id) {
|
||||
return \mfResponse::NotFound(["message" => "Preorder not found"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($activation_date) {
|
||||
try {
|
||||
$adate = new \DateTime($activation_date);
|
||||
$adate->setTimezone(new \DateTimeZone("Europe/Vienna"));
|
||||
$adate->setTime(2, 0, 0); // set time to 2:00:00
|
||||
// activation date cannot be in the future
|
||||
if($adate > new \DateTime()) {
|
||||
return \mfResponse::BadRequest(["message" => "Activation date can only be in the past"]);
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
return \mfResponse::BadRequest(["message" => "Invalid activation_date format"]);
|
||||
}
|
||||
}
|
||||
|
||||
// set status to 500
|
||||
if($preorder->status->code < 500) {
|
||||
if($preorder->status->code < 242) {
|
||||
return \mfResponse::BadRequest(["message" => "Service cannot be activated, because Construction work is not yet finished"]);
|
||||
}
|
||||
|
||||
$new_status = \PreorderstatusModel::getFirst(["code" => 500]);
|
||||
if(!$new_status) {
|
||||
return \mfResponse::InternalServerError();
|
||||
}
|
||||
$preorder->status_id = $new_status->id;
|
||||
$preorder->save();
|
||||
|
||||
if($adate) {
|
||||
$history = \PreorderHistoryModel::getLastStatusChangeTo($preorder->id, 500);
|
||||
if($history) {
|
||||
$history->changed = $adate->getTimestamp();
|
||||
$history->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return \mfResponse::Ok(["message" => "Status successfully updated."]);
|
||||
|
||||
@@ -856,11 +856,31 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
if(trim($this->post['orderDate'])) {
|
||||
$order_date = trim($this->post['orderDate']);
|
||||
try {
|
||||
$order_date = new DateTime(trim($this->post['orderDate']));
|
||||
$order_date->setTime(4, 0, 0);
|
||||
$order_date->setTimezone(new DateTimeZone('Europe/Vienna'));
|
||||
|
||||
// cannot be older than 14 days
|
||||
$now = new DateTime();
|
||||
$now->setTime(4, 0, 0);
|
||||
$now->setTimezone(new DateTimeZone('Europe/Vienna'));
|
||||
$diff = $now->diff($order_date);
|
||||
if($diff->days > 14) {
|
||||
return mfResponse::BadRequest(["message" => "orderDate cannot be older than 14 days"]);
|
||||
}
|
||||
$preorder_data['order_date'] = $order_date->getTimestamp();
|
||||
} catch(Exception $e) {
|
||||
$this->log->debug(__METHOD__.": Error parsing orderDate: " . $e->getMessage());
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
||||
/*$order_date = trim($this->post['orderDate']);
|
||||
$m = [];
|
||||
if(preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d)$/', $order_date, $m)) {
|
||||
$preorder_data['order_date'] = mktime(4, 0, 0, $m[2], $m[3], $m[1]);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if($is_additional_order) {
|
||||
|
||||
Reference in New Issue
Block a user