Browse code

Initial commit

Benjamin Roth authored on07/09/2015 15:02:25
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,184 @@
1
+<?php
2
+
3
+/**
4
+ * eSales Media oxVoucher for Contao Open Source CMS
5
+ *
6
+ * Copyright (c) 2015 eSales Media
7
+ *
8
+ * @author  Benjamin Roth [benjamin@esales-media.de]
9
+ * @license proprietary
10
+ */
11
+
12
+namespace eSM_oxVoucher;
13
+
14
+class ModuleVoucherDetails extends ModuleVoucher
15
+{
16
+	/**
17
+	 * Template
18
+	 * @var string
19
+	 */
20
+	protected $strTemplate = 'mod_oxvoucher_details';
21
+
22
+	protected $blnHide = false;
23
+
24
+	/**
25
+	 * Parse the template
26
+	 * @return string
27
+	 */
28
+	public function generate()
29
+	{
30
+		if (TL_MODE == 'BE')
31
+		{
32
+			/** @var \BackendTemplate|object $objTemplate */
33
+			$objTemplate = new \BackendTemplate('be_wildcard');
34
+
35
+			$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['oxvoucher_details'][0]) . ' ###';
36
+			$objTemplate->title = $this->headline;
37
+			$objTemplate->id = $this->id;
38
+			$objTemplate->link = $this->name;
39
+			$objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
40
+
41
+			return $objTemplate->parse();
42
+		}
43
+
44
+		$this->importOxDbInstance();
45
+
46
+		$strBuffer = parent::generate();
47
+
48
+		if (!$this->blnHide)
49
+		{
50
+			return $strBuffer;
51
+		}
52
+	}
53
+
54
+
55
+	/**
56
+	 * Compile the current element
57
+	 */
58
+	protected function compile()
59
+	{
60
+		if (\Input::get('voucher_search') || \Input::post('FORM_SUBMIT') == 'eSM_oxVoucher_details')
61
+		{
62
+			if (\Input::post('FORM_SUBMIT') == 'eSM_oxVoucher_details')
63
+			{
64
+				$objSQL = $this->oxDB->prepare("SELECT v.* FROM oxvouchers v, oxvoucherseries vs WHERE vs.OXID = v.OXVOUCHERSERIEID AND LOWER(v.OXID) = ? AND vs.OXDISCOUNTTYPE = 'absolute'");
65
+				$objVoucher = $objSQL->execute(strtolower(\Input::post('OXID')));
66
+			} else {
67
+				$objSQL = $this->oxDB->prepare("SELECT v.* FROM oxvouchers v, oxvoucherseries vs WHERE vs.OXID = v.OXVOUCHERSERIEID AND LOWER(v.OXVOUCHERNR) = ? AND vs.OXDISCOUNTTYPE = 'absolute'");
68
+				$objVoucher = $objSQL->execute(strtolower(\Input::get('voucher_search')));
69
+			}
70
+
71
+			if ($objVoucher->numRows < 1 || $objVoucher->numRows > 1)
72
+			{
73
+				if (!\Input::get('voucher_search'))
74
+				{
75
+					$this->Template->noVoucher = $GLOBALS['TL_LANG']['MSC']['oxVoucher']['supplyVoucherNo'];
76
+				} else {
77
+					$this->Template->noVoucher = sprintf($GLOBALS['TL_LANG']['MSC']['oxVoucher']['noVoucher'],\Input::get('voucher_search'));
78
+				}
79
+				return;
80
+			}
81
+
82
+			$objVoucher = new VoucherHandler($objVoucher->OXID);
83
+			$blnIsValid = $objVoucher->isValid();
84
+
85
+			// Voucher remaining value
86
+			$fUsedVal = $objVoucher->getUsedVal();
87
+			$fRemainingVal = ($blnIsValid ? $objVoucher->getRemainingVal() : (!$objVoucher->isValidTime() ? $objVoucher->getRemainingVal() : 0.00));
88
+
89
+			// Update voucher
90
+			if (\Input::post('FORM_SUBMIT') == 'eSM_oxVoucher_details')
91
+			{
92
+				$blnInvalidate = false;
93
+
94
+				if (\Input::post('voucher_deductAll'))
95
+				{
96
+					$fDeductVal = $fRemainingVal;
97
+				} else {
98
+					$fDeductVal = floatval(\Input::post('voucher_deductValue'));
99
+
100
+				}
101
+
102
+				if ($fDeductVal <= $fRemainingVal && $fDeductVal > 0) {
103
+					$objVoucher->deductValue($fDeductVal);
104
+
105
+					$strMessage = sprintf($GLOBALS['TL_LANG']['MSC']['oxVoucher']['voucher_confirm'],$this->getFormattedNumber($fDeductVal),$this->getFormattedNumber($objVoucher->getRemainingVal()));
106
+					$strType = 'confirm';
107
+
108
+					if ($fDeductVal == $fRemainingVal)
109
+					{
110
+						$strMessage = sprintf($GLOBALS['TL_LANG']['MSC']['oxVoucher']['voucher_confirm_depleted'],$this->getFormattedNumber($fDeductVal));
111
+					}
112
+				} else if ($fDeductVal > $fRemainingVal)
113
+				{
114
+					$strMessage = sprintf($GLOBALS['TL_LANG']['MSC']['oxVoucher']['voucher_error_gtv'],$this->getFormattedNumber($fDeductVal),$this->getFormattedNumber($objVoucher->getRemainingVal()));
115
+					$strType = 'error';
116
+				} else
117
+				{
118
+					$strMessage = $GLOBALS['TL_LANG']['MSC']['oxVoucher']['voucher_error_zero'];
119
+					$strType = 'error';
120
+				}
121
+
122
+				$this->setMessage($strMessage,$strType);
123
+				$this->reload();
124
+			}
125
+
126
+
127
+
128
+			// Voucher time
129
+			$Today = new \Date();
130
+
131
+			// Template Vars
132
+			if (!is_null($objVoucher->oxdateused))
133
+			{
134
+				$strInvalid = sprintf($GLOBALS['TL_LANG']['MSC']['oxVoucher']['invalid_used'], \Date::parse(\Date::getNumericDateFormat(), $objVoucher->oxdateused));
135
+			} else if (!$objVoucher->isValidTime()) {
136
+				$strInvalid = $GLOBALS['TL_LANG']['MSC']['oxVoucher']['invalid_date'];
137
+			} else {
138
+				$strInvalid = $GLOBALS['TL_LANG']['MSC']['oxVoucher']['invalid'];
139
+			}
140
+			$arrData = array
141
+			(
142
+				'titleDetails'      => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['detailsTitle'],
143
+				'titleDeduct'       => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['deductTitle'],
144
+
145
+				'lblVoucherNo'      => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['lblVoucherNo'],
146
+				'lblSerieNo'        => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['lblSerieNo'],
147
+				'lblSerieDesc'      => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['lblSerieDesc'],
148
+				'lblSerieDiscount'  => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['lblSerieDiscount'],
149
+				'lblValidFrom'      => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['lblValidFrom'],
150
+				'lblValidTil'       => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['lblValidTil'],
151
+				'lblRemainingVal'   => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['lblRemainingVal'],
152
+
153
+				'voucherOxid'       => $objVoucher->oxid,
154
+				'voucherNo'         => $objVoucher->oxvouchernr,
155
+				'serieNo'           => $objVoucher->oxserienr,
156
+				'serieDesc'         => $objVoucher->oxseriedescription,
157
+				'validFrom'         => (!is_null($objVoucher->oxbegindate) ? \Date::parse(\Date::getNumericDatimFormat(),$objVoucher->oxbegindate) : ''),
158
+				'validTil'          => (!is_null($objVoucher->oxenddate) ? \Date::parse(\Date::getNumericDatimFormat(),$objVoucher->oxenddate) : ''),
159
+				'serieDiscount'     => $this->getFormattedNumber($objVoucher->oxseriediscount),
160
+				'usedVal'           => $fUsedVal,
161
+				'remainingVal'      => $fRemainingVal,
162
+				'fRemainingVal'     => $this->getFormattedNumber($fRemainingVal),
163
+
164
+				'submitLabel'       => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['deductSubmitLabel'],
165
+				'valueLabel'        => $GLOBALS['TL_LANG']['MSC']['oxVoucher']['valueLabel'],
166
+				'maxValueLabel'     => sprintf($GLOBALS['TL_LANG']['MSC']['oxVoucher']['maxValueLabel'],$this->getFormattedNumber($fRemainingVal)),
167
+
168
+				'isValid'           => $blnIsValid,
169
+				'invalid'           => $strInvalid,
170
+
171
+				'messages'          => $this->getMessages(),
172
+			);
173
+
174
+			$this->Template->setData($arrData);
175
+		} else
176
+		{
177
+
178
+			$this->blnHide = true;
179
+		}
180
+
181
+
182
+	}
183
+
184
+}
0 185
\ No newline at end of file