diff --git a/Layout/default/Invoice/Index.php b/Layout/default/Invoice/Index.php
index 5f269cc04..32fcff61e 100644
--- a/Layout/default/Invoice/Index.php
+++ b/Layout/default/Invoice/Index.php
@@ -342,7 +342,8 @@ $pagination_entity_name = "Rechnungen";
=($invoice->billing_type == "sepa") ? "SEPA" : "Überweisung"?> |
=($invoice->billing_delivery == "email") ? "Email" : "Papier"?> |
- $invoice->id])?>" title="CSV-Download">
+ $invoice->id])?>" title="CSV-Download">
+ $invoice->id])?>" title="CSV-Download">
|
diff --git a/application/Invoice/InvoiceController.php b/application/Invoice/InvoiceController.php
index 1871ffd2e..f860ed672 100644
--- a/application/Invoice/InvoiceController.php
+++ b/application/Invoice/InvoiceController.php
@@ -212,6 +212,112 @@ class InvoiceController extends mfBaseController {
exit;
}
+ protected function downloadInvoiceVoiceDetailsAction() {
+ $id = $this->request->id;
+ if (!is_numeric($id) || !$id) {
+ $this->layout()->setFlash("Rechnung nicht gefunden", "error");
+ $this->redirect("Invoice");
+ }
+
+ $invoice = new Invoice($id);
+ if (!$invoice->id) {
+ $this->layout()->setFlash("Rechnung nicht gefunden", "error");
+ $this->redirect("Invoice");
+ }
+
+ $csv = "Startzeit;Abgehende Nummer;Zielnummer;Zone;Dauer;Kosten\n";
+
+ $destinations_cache = [];
+
+ foreach($invoice->voicenumbers as $voicenumber) {
+ $start_date = new DateTime($voicenumber->start_date);
+ //$start_date->setTimezone(new DateTimeZone("Europe/Vienna"));
+ $start_date->setTime(0,0,0);
+ $end_date = new DateTime($voicenumber->end_date);
+ //$end_date->setTimezone(new DateTimeZone("Europe/Vienna"));
+ $end_date->setTime(23,59,59);
+
+ foreach(VoiceCallHistoryModel::getVoiceCallHistoryAsEntity([
+ "voice_account" => $voicenumber->voicenumber,
+ "start" => [
+ "from" => $start_date->getTimestamp(),
+ "to" => $end_date->getTimestamp()
+ ],
+ "billable" => 1,
+ ], null, 0, ["key" => "start", "order" => "ASC"]) as $call) {
+ if(!$call->contract_id) continue;
+
+ //$voiceplan = new Voiceplan($voicenumber->voiceplan_id);
+ $voiceplan = VoiceplanModel::getFirst(["name" => $voicenumber->voiceplan]);
+ if(!$voiceplan) {
+ $this->log->warning(__METHOD__.": Voiceplan not found");
+ };
+
+ $number = $voicenumber->voicenumber;
+ $dest_nummer = $call->destination;
+ if (substr($dest_nummer, 0, 2) == "00") {
+ $dest_nummer = substr($dest_nummer, 2);
+ }
+
+ if (substr($dest_nummer, 0, 1) == "+") {
+ $dest_nummer = substr($dest_nummer, 1);
+ }
+
+ if (array_key_exists($dest_nummer, $destinations_cache)) {
+ $destination = $destinations_cache[$dest_nummer];
+ } else {
+ $destination = $voiceplan->getDestinationByNumber($dest_nummer);
+ if (!$destination) {
+ die("Destination für Zielrufnummer " . $call->destination . " nicht gefunden");
+ }
+ $destinations_cache[$dest_nummer] = $destination;
+ }
+ //var_dump($destination);
+
+ $zone = $destination->voiceplanzone;
+
+ if (!$zone) {
+ die("Keine Zone für Destination " . $dest_nummer . " gefunden");
+ }
+
+ //var_dump($zone);exit;
+
+ // inc_first - first minimumm duration to bill
+ // inc - subsequent minimum duration to bill
+ $inc_first = $zone->increment_first;
+ $inc = $zone->increment;
+
+ $billable_duration = $call->duration;
+ if ($billable_duration <= 0) continue;
+
+ // calculate price of first duration unit
+ // then subtract first minimum duration from duration
+ $sec_price = $zone->price / 60;
+ $call_price = $inc_first * $sec_price;
+ $billable_duration -= $inc_first;
+
+ // calculate price of remaining duration and make sure to bill in full duration units
+ if ($billable_duration > 0) {
+ $multi = ceil($billable_duration / $inc);
+ $call_price += ($multi * $inc) * $sec_price;
+ }
+
+ $csv .= '"'.$call->start.'";';
+ $csv .= '"'.$call->source.'"; ';
+ $csv .= '"'.$call->destination.'"; ';
+ $csv .= '"'.$zone->name.'"; ';
+ $csv .= $call->duration.'; ';
+ $csv .= '"'.str_replace(".",",", $call_price).'"';
+ $csv .= "\n";
+ }
+
+ }
+
+ header("Content-type: text/csv; charset=utf-8");
+ header('Content-disposition: attachment; filename="'.$invoice->invoice_number.'-egn.csv"');
+ echo $csv;
+ exit;
+ }
protected function createJob() {
$r = $this->request;