first commit

This commit is contained in:
2025-03-12 17:06:23 +01:00
commit 2241f7131f
13185 changed files with 1692479 additions and 0 deletions

View File

@@ -0,0 +1,297 @@
<?php
/**
* SOTESHOP/stTaxPlugin
*
* Ten plik należy do aplikacji stTaxPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @package stTaxPlugin
* @subpackage actions
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
* @version $Id$
* @author Krzysztof Bebło <krzysztof.beblo@sote.pl>
*/
/**
* stTaxBackend actions.
*
* @package stTaxPlugin
* @subpackage actions
*/
class stTaxBackendActions extends autoStTaxBackendActions
{
public function executeChangePriceType()
{
$type = $this->getRequestParameter('type');
$config = stConfig::getInstance(sfContext::getInstance(), 'stProduct');
$config->set('price_type', $type);
$config->save();
return $this->redirect($this->getRequest()->getReferer());
}
public function executeSave()
{
$tax = TaxPeer::retrieveByPK($this->getRequestParameter('id'));
if (!$tax || $tax->getVat() == $this->getRequestParameter('tax[vat]'))
{
return parent::executeSave();
}
$this->tax = $tax;
}
public function updateTaxFromRequest()
{
if ($this->hasRequestParameter('update_price') && $this->tax->getVat() != $this->getRequestParameter('tax[vat]'))
{
$this->tax->setUpdateResume(array('prev_value' => $this->tax->getVat(), 'type' => $this->getRequestParameter('update_price')));
}
parent::updateTaxFromRequest();
}
public function executeUpdatePrice()
{
$tax = TaxPeer::retrieveByPK($this->getRequestParameter('id'));
if ($params = $tax->getUpdateResume())
{
$c = new Criteria();
$c->add(ProductPeer::TAX_ID, $tax->getId());
$steps['products'] = ProductPeer::doCount($c);
$c = new Criteria();
$c->add(DeliveryPeer::TAX_ID, $tax->getId());
$steps['deliveries'] = DeliveryPeer::doCount($c);
$this->steps = $steps['products'] + $steps['deliveries'];
stTaxProgressBar::setParam('steps', $steps);
}
$params['id'] = $tax->getId();
$params['value'] = $tax->getVat();
stTaxProgressBar::setParam('tax', $params);
$this->params = $params;
$i18n = $this->getContext()->getI18n();
if (isset($params['type']))
{
$this->title = $i18n->__('Przeliczanie cen z %type% dla stawki VAT %tax%%', array(
'%type%' => $i18n->__($params['type'] == 'netto' ? 'brutto na netto' : 'netto na brutto'),
'%tax%' => $params['value']
));
}
else
{
$this->title = $i18n->__('Przeliczanie cen dla stawki VAT %tax%%', array('%tax%' => $params['value']));
}
$this->tax = $tax;
}
public function validateEdit()
{
$tax = $this->getTaxOrCreate();
$i18n = $this->getContext()->getI18N();
$request = $this->getRequest();
if ($tax->getUpdateResume())
{
$message = $i18n->__('Wykryto zmiane stawki VAT. Kliknij').' <a href="'.$this->getController()->genUrl('@stTaxPlugin?action=updatePrice&id='.$tax->getId()).'">'.$i18n->__('tutaj').'</a>, '.$i18n->__('aby dokończyć poprzednią aktualizację cen');
$request->setError('tax', $message);
}
if ($request->getMethod() == sfRequest::POST)
{
$data = $this->getRequestParameter('tax');
$config = stConfig::getInstance('stTaxBackend');
if (isset($data['is_active']) && isset($data['rates_by_country']) && $config->get('is_customer_eu_tax_enabled'))
{
$codes = stTax::getRequiredCountriesCodes();
foreach ($codes as $code)
{
if (!isset($data['rates_by_country'][$code]) || $data['rates_by_country'][$code] === "")
{
$request->setError('tax{rates_by_country}', $i18n->__('Proszę uzupełnić pole.'));
$request->setError('tax{rates_by_country}{'.$code.'}', $i18n->__('Proszę uzupełnić pole.'));
}
}
}
if (!isset($data['is_active']) && !$tax->isNew() && $tax->countProducts() > 0)
{
$request->setError('tax{is_active}', $i18n->__('Nie można wyłączyć stawki VAT "%%tax%%", ponieważ ma przypisane produkty', array('%%tax%%' => $tax->getVatName())));
}
}
return !$request->hasErrors();
}
/**
* {@inheritDoc}
*/
public function getLabels()
{
$i18n = $this->getContext()->getI18N();
$labels = parent::getLabels();
$labels['tax'] = $i18n->__('Zmiana stawki VAT');
return $labels;
}
public function handleErrorSave()
{
$this->handleErrorEdit();
$this->setTemplate('edit');
return sfView::SUCCESS;
}
public function saveTax($tax)
{
$ret = parent::saveTax($tax);
if ($this->hasRequestParameter('update_price'))
{
$con = Propel::getConnection();
$sql = sprintf('UPDATE %1$s, %2$s SET %3$s = ? WHERE %4$s = %5$s AND %6$s = ?',
ProductOptionsValuePeer::TABLE_NAME,
ProductPeer::TABLE_NAME,
ProductOptionsValuePeer::IS_UPDATED,
ProductOptionsValuePeer::PRODUCT_ID,
ProductPeer::ID,
ProductPeer::TAX_ID);
$st = $con->prepareStatement($sql);
$st->setBoolean(1, false);
$st->setInt(2, $tax->getId());
$st->executeQuery();
$this->redirect('stTaxBackend/updatePrice?id='.$tax->getId());
}
return $ret;
}
public function validateConfig()
{
$request = $this->getRequest();
if ($request->getMethod() == sfRequest::POST)
{
sfLoader::loadHelpers(array('Helper', 'stUrl'));
$data = $this->getRequestParameter('config');
$i18n = $this->getContext()->getI18N();
if (isset($data['is_eu_tax_enabled']))
{
if (!stConfig::getInstance('stShopInfoBackend')->get('country'))
{
$error = $i18n->__('Do poprawnego działania %%name%% wymagane jest ustawienie kraju siedziby firmy w %%link%%', array(
'%%name%%' => $i18n->__('VAT UE dla firm'),
'%%link%%' => st_link_to($i18n->__('Konfiguracji informacji o sklepie'), '@stShopInfoPlugin?action=config', array('target' => '_blank'))
));
$request->setError('config{is_eu_tax_enabled}',$error);
}
}
if (isset($data['is_customer_eu_tax_enabled']))
{
$errors = array();
if (!stConfig::getInstance('stShopInfoBackend')->get('country'))
{
$errors[] = $i18n->__('Do poprawnego działania %%name%% wymagane jest ustawienie kraju siedziby firmy w %%link%%', array(
'%%name%%' => $i18n->__('VAT UE dla konsumentów'),
'%%link%%' => st_link_to($i18n->__('Konfiguracji informacji o sklepie'), '@stShopInfoPlugin?action=config', array('target' => '_blank'))
));
}
$required = stTax::getRequiredCountriesCodes();
$i18n = $this->getContext()->getI18N();
foreach (TaxPeer::doSelectActive() as $tax)
{
if ($tax->isSystemDefault())
{
continue;
}
$rates = $tax->getRatesByCountry();
foreach ($required as $code)
{
if (!isset($rates[$code]) || $rates[$code] === "")
{
$errors[] = $i18n->__('is.customer.eu.tax.enabled.help');
break 2;
}
}
}
if ($errors)
{
$request->setError('config{is_customer_eu_tax_enabled}', implode('<br>', $errors));
}
}
}
return !$request->hasErrors();
}
/**
* {@inheritDoc}
*/
protected function getTaxOrCreate($id = 'id')
{
$tax = parent::getTaxOrCreate($id);
if ($tax->isSystemDefault())
{
$this->hideField('rates_by_country');
}
return $tax;
}
protected function deleteTax($tax)
{
if ($tax->countProducts() > 0)
{
$i18n = $this->getContext()->getI18N();
throw new Exception($i18n->__('Nie można usunąć stawki VAT "%%tax%%", ponieważ ma przypisane produkty', array('%%tax%%' => $tax->getVatName())));
}
return parent::deleteTax($tax);
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* SOTESHOP/stTaxPlugin
*
* Ten plik należy do aplikacji stTaxPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @package stTaxPlugin
* @subpackage actions
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
* @version $Id$
* @author Krzysztof Bebło <krzysztof.beblo@sote.pl>
*/
/**
* Klasa stTaxBackendComponents
*
* @package stTaxPlugin
* @subpackage actions
*/
class stTaxBackendComponents extends autoStTaxBackendComponents
{
public function executeRatesByCountry()
{
$rates = stTax::getEUTaxRates();
$countries = stTax::getCountriesForConsumerEuRates();
$requiredCountries = stTax::getRequiredCountriesCodes();
$requiredRates = array();
$moreRates = array();
$i18n = $this->getContext()->getI18N();
$config = stConfig::getInstance('stShopInfoBackend');
foreach ($rates as $countryCode => $rate)
{
if ($config->get('country') != $countryCode)
{
$allRates = array($rate['normal']);
$allRates = array_merge($allRates, $rate['reduced']);
$allRates = array_combine($allRates, $allRates);
$allRates = array_map(function($value) {
return $value . ' %';
}, $allRates);
$defaultRate = key($allRates);
$allRates[$defaultRate] = $allRates[$defaultRate] . ' ' . $i18n->__('Podstawowa');
if (in_array($countryCode, $requiredCountries))
{
$requiredRates[$countryCode] = $allRates;
}
else
{
$moreRates[$countryCode] = $allRates;
}
}
}
$this->requiredRates = $requiredRates;
$this->moreRates = $moreRates;
$this->countries = $countries;
$this->values = $this->tax->getRatesByCountry();
}
}

View File

@@ -0,0 +1,57 @@
generator:
class: stAdminGenerator
param:
model_class: Tax
theme: simple
head:
package: stTaxPlugin
documentation:
pl: https://www.sote.pl/docs/vat
en: https://www.soteshop.com/docs/tax
list:
title: Lista
menu:
display: [list]
fields:
list: {name: Lista stawek VAT, action: "@stTaxPlugin?action=list"}
display: [vat_name, _vat_list, is_default, is_active]
fields:
is_active: {name: Aktywna}
vat_list: {name: Domyślna stawka, sort_field: tax.vat}
vat_name: {name: Nazwa}
is_default: {name: Domyślny VAT}
actions:
_create: {name: Dodaj}
object_actions:
_edit: -
_delete: -
empty_message: Brak stawek VAT
edit:
title: Edycja stawki VAT
display:
NONE: [is_active, _edit_is_default, _vat_name, _vat, ~rates_by_country]
fields:
is_active: {name: Aktywna, required: false }
vat: {name: Domyślna stawka, help: "default.vat.rate.help"}
vat_name: {name: Nazwa}
edit_is_default: {name: Domyślny VAT, help: Domyślnie wybrana stawka VAT podczas dodawania nowego produktu lub dostawy}
rates_by_country: {name: VAT UE dla konsumentów, help: "vat.ue.for.consumer.help"}
actions:
_delete: {name: Usuń}
_list: {name: Lista}
_save: {name: Zapisz}
_save_and_add: {name: Zapisz i dodaj}
config:
menu: {use: list.menu}
title: Konfiguracja
display: [is_eu_tax_enabled, is_customer_eu_tax_enabled]
fields:
is_eu_tax_enabled: {name: "Włącz VAT UE dla firm", type: checkbox_tag}
is_customer_eu_tax_enabled: {name: "Włącz VAT UE dla konsumentów", type: checkbox_tag, help: "is.customer.eu.tax.enabled.help"}
actions:
_save: {name: Zapisz}

View File

@@ -0,0 +1,2 @@
<?php echo input_hidden_tag('tax[edit_is_default]', $tax->getIsDefault()) ?>
<?php echo st_admin_checkbox_tag('tax[edit_is_default]', 1, $tax->getIsDefault(), array('disabled' => $tax->getIsDefault())) ?>

View File

@@ -0,0 +1,39 @@
<?php if (!empty($requiredRates)): ?>
<?php echo st_admin_table_start() ?>
<thead>
<tr>
<th style="width: 200px"><?php echo __("Kraj dostawy wg konfiguracji") ?></th>
<th><?php echo __("Stawka VAT") ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($countries as $countryCode => $country):
if (!isset($requiredRates[$countryCode])) continue;
$rates = $requiredRates[$countryCode];
$value = isset($values[$countryCode]) && $values[$countryCode] !== "" ? $values[$countryCode] : null;
?>
<tr>
<td style="text-align: right"><b><?php echo $country ?></b></td>
<td><?php echo select_tag('tax[rates_by_country]['.$countryCode.']', options_for_select($rates, $value, array('include_custom' => '---')), array(
'class' => null !== $value ? 'not-required' : '',
'style' => 'width: 200px',
)) ?></td>
</tr>
<?php endforeach ?>
</tbody>
<?php echo st_admin_table_end() ?>
<?php endif ?>
<?php echo st_admin_table_start(array(
array('label' => __("Kraj"), 'options' => array('style' => 'width: 200px')),
array('label' => __("Stawka VAT")),
), array('style' => 'margin-top: 10px')) ?>
<tbody>
<?php foreach ($countries as $countryCode => $country): if (!isset($moreRates[$countryCode])) continue; $rates = $moreRates[$countryCode] ?>
<tr>
<td style="text-align: right"><?php echo $country ?></td>
<td><?php echo select_tag('tax[rates_by_country]['.$countryCode.']', options_for_select($rates, isset($values[$countryCode]) ? $values[$countryCode] : null, array('include_custom' => '---')), array('style' => 'width: 200px', 'class' => 'not-required')) ?></td>
</tr>
<?php endforeach ?>
</tbody>
<?php echo st_admin_table_end() ?>

View File

@@ -0,0 +1,13 @@
<?php
echo object_input_tag($tax, $method, array(
'size' => 7,
'control_name' => $name,
'disabled' => $tax->getIsSystemDefault(),
));
if ($tax->getIsSystemDefault())
{
echo input_hidden_tag($name, $tax->$method());
}
?> %

View File

@@ -0,0 +1 @@
<?php echo $tax->getVat() ?> %

View File

@@ -0,0 +1,12 @@
<?php
echo object_input_tag($tax, $method, array(
'size' => 14,
'control_name' => $name,
'disabled' => $tax->getIsSystemDefault(),
));
if ($tax->getIsSystemDefault())
{
echo input_hidden_tag($name, $tax->$method());
}

View File

@@ -0,0 +1,40 @@
<?php use_helper('stAdminGenerator') ?>
<?php st_include_partial('stTaxBackend/header', array('related_object' => $tax, 'title' => __('Edycja stawki VAT'), 'route' => 'stTaxBackend/edit?id='.$tax->getId())) ?>
<div id="sf_admin_content">
<div class="form-errors">
<h2><?php echo __('Wykryto zmiane stawki VAT z %from%% na %to%%. Wybierz metodę przeliczenia obecnych cen w sklepie', array('%from%' => $tax->getVat(), '%to%' => $sf_request->getParameter('tax[vat]'))) ?></h2>
</div>
<form class="admin_form" id="admin_edit_form" action="<?php echo st_url_for('stTaxBackend/edit?id='.$tax->getId()) ?>" method="post">
<fieldset>
<div class="content">
<?php
foreach ($sf_request->getParameter('tax') as $name1 => $value1)
{
if (is_array($value1))
{
foreach ($value1 as $name2 => $value2)
{
echo input_hidden_tag('tax['.$name1.']['.$name2.']', $value2);
}
}
else
{
echo input_hidden_tag('tax['.$name1.']', $value1);
}
}
?>
<?php echo st_admin_get_form_field('update_price', __('Przelicz').':', array('brutto' => __('netto na brutto'), 'netto' => __('brutto na netto')), 'select_tag', array(
'help' => __('<b>netto na brutto</b> - ceny brutto ulegną zmianie<br/><b>brutto na netto</b> - ceny netto ulegną zmianie')
.'<br /><b>'.__('przeliczeniu ulegną').':</b><ul style="list-style: circle inside"><li>'.__('ceny produktów').'</li><li>'.__('koszty dostaw').'</li></ul>')); ?>
</div>
</fieldset>
<?php echo st_get_admin_actions_head(); ?>
<?php echo st_get_admin_action('reset', __('Anuluj', null, 'stAdminGeneratorPlugin'), 'stTaxBackend/edit?id='.$tax->getId()); ?>
<?php echo st_get_admin_action('save', __('Zapisz', null, 'stAdminGeneratorPlugin')); ?>
<?php echo st_get_admin_actions_foot(); ?>
</form>
</div>
<?php st_include_partial('stTaxBackend/footer', array('related_object' => $tax)) ?>

View File

@@ -0,0 +1,10 @@
<?php use_helper('stProgressBar', 'stAdminGenerator', 'stUrl'); ?>
<?php echo st_get_admin_head('stTaxPlugin', null, __('Zarządzaj stawkami VAT'), array('stMailPlugin')) ?>
<div id="sf_admin_content">
<h2 id="st_admin_title"><?php echo __('Przeliczanie cen dla stawki VAT %tax%%', array('%tax%' => $tax->getVat())) ?></h2>
<p><?php echo __('Aktualizacja cen została zakończona pomyślnie.<br/>%return_link%', array('%return_link%' => st_link_to(__('Powróć do edycji'),'stTaxBackend/edit?id='.$this->tax['id']))); ?></p>
</div>
<br class="st_clear_all" />
<?php echo st_get_admin_foot() ?>

View File

@@ -0,0 +1,28 @@
<?php use_helper('stProgressBar', 'stAdminGenerator'); ?>
<?php st_include_partial('stTaxBackend/header', array('related_object' => $tax, 'title' => $title, 'route' => 'stTaxBackend/edit?id='.$tax->getId())) ?>
<style type="text/css">
#tax_progress_bar {
padding: 10px;
text-align: center;
width: 280px;
margin: 0 auto;
}
#tax_progress_bar .stPrograssBar-main-div {
margin: 0 auto;
}
</style>
<div id="sf_admin_content">
<div class="fieldset" id="tax_progress_bar">
<?php if (isset($params['type'])): ?>
<?php echo progress_bar('stTax', 'stTaxProgressBar', 'updateProductPrice', $steps); ?>
<?php else: ?>
<p><?php echo __('Aktualizacja cen została zakończona pomyślnie.<br/>%return_link%', array('%return_link%' => st_link_to(__('Powróć do edycji'),'stTaxBackend/edit?id='.$tax->getId()))); ?></p>
<?php endif; ?>
</div>
</div>
<?php st_include_partial('stTaxBackend/footer', array('related_object' => $tax)) ?>

View File

@@ -0,0 +1,13 @@
fields:
tax{vat}:
required:
msg: Podaj VAT
sfNumberValidator:
nan_error: VAT musi być liczbą, a części dziesiętne należy wprowadzić z kropką (.)
min: 0
min_error: VAT nie może być mniejszy niż 0 %
max: 99.99
max_error: VAT musi być mniejszy niż 100 %
tax{vat_name}:
required:
msg: Podaj nazwę stawki VAT

View File

@@ -0,0 +1,13 @@
fields:
tax{vat}:
required:
msg: Podaj VAT
sfNumberValidator:
nan_error: VAT musi być liczbą, a części dziesiętne należy wprowadzić z kropką (.)
min: 0
min_error: VAT nie może być mniejszy niż 0 %
max: 99.99
max_error: VAT musi być mniejszy niż 100 %
tax{vat_name}:
required:
msg: Podaj nazwę stawki VAT