Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tarea #2313 - redireccionar al documento previo al crear nuevo cliente #1586

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion Core/Base/AjaxForms/SalesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ public function getModel(bool $reload = false): SalesDocument
*/
public function renderSalesForm(SalesDocument $model, array $lines): string
{
$url = $this->url();

if($model->primaryColumnValue()){
$url = Tools::urlAddParams($url, ['code' => $model->primaryColumnValue()]);
}

return '<div id="salesFormHeader">' . SalesHeaderHTML::render($model) . '</div>'
. '<div id="salesFormLines">' . SalesLineHTML::render($lines, $model) . '</div>'
. '<div id="salesFormFooter">' . SalesFooterHTML::render($model) . '</div>'
. SalesModalHTML::render($model, $this->url(), $this->user, $this->permissions);
. SalesModalHTML::render($model, $url, $this->user, $this->permissions);
}

public function series(string $type = ''): array
Expand Down Expand Up @@ -320,6 +326,12 @@ protected function loadData($viewName, $view)

// data not found?
$view->loadData($code);
if($this->request->query->has(Cliente::primaryColumn())){
$cliente = new Cliente();
$cliente->loadFromCode($this->request->query->get(Cliente::primaryColumn()));
$view->model->setSubject($cliente);
$view->model->save();
}
$action = $this->request->request->get('action', '');
if ('' === $action && empty($view->model->primaryColumnValue())) {
Tools::log()->warning('record-not-found');
Expand Down
7 changes: 3 additions & 4 deletions Core/Base/AjaxForms/SalesModalHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,8 @@ protected static function modalClientes(Translator $i18n, string $url, User $use
. '</tr>';
}

$linkAgent = '';
if ($user->codagente) {
$linkAgent = '&codagente=' . $user->codagente;
if($user->codagente){
$url = Tools::urlAddParams($url, ['codagente' => $user->codagente]);
}

return '<div class="modal" id="findCustomerModal" tabindex="-1" aria-hidden="true">'
Expand All @@ -322,7 +321,7 @@ protected static function modalClientes(Translator $i18n, string $url, User $use
. '</div>'
. '<table class="table table-hover mb-0">' . $trs . '</table></div>'
. '<div class="modal-footer bg-light">'
. '<a href="EditCliente?return=' . urlencode($url) . $linkAgent . '" class="btn btn-block btn-success">'
. '<a href="EditCliente?return=' . urlencode($url) . '" class="btn btn-block btn-success">'
. '<i class="fas fa-plus fa-fw"></i> ' . $i18n->trans('new')
. '</a>'
. '</div>'
Expand Down
2 changes: 1 addition & 1 deletion Core/Controller/EditCliente.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function insertAction()
$returnUrl = $this->request->query->get('return');
if (!empty($returnUrl)) {
$model = $this->views[$this->active]->model;
$this->redirect($returnUrl . '?' . $model->primaryColumn() . '=' . $model->primaryColumnValue());
$this->redirect(Tools::urlAddParams($returnUrl, [$model::primaryColumn() => $model->primaryColumnValue()]));
}

return true;
Expand Down
16 changes: 16 additions & 0 deletions Core/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ public static function timeToDateTime(int $time): string
return date(self::DATETIME_STYLE, $time);
}

public static function urlAddParams(string $url, array $params = []): string
{
$urlQuery = parse_url($url, PHP_URL_QUERY);
$urlPath = parse_url($url, PHP_URL_PATH);
$urlParams = [];

if ($urlQuery){
parse_str($urlQuery, $urlParams);
}

$urlParams = array_merge($urlParams, $params);
$paramsQuery = '?' . http_build_query($urlParams);

return $urlPath . $paramsQuery;
}

private static function settingsLoad(): void
{
if ('' === Tools::config('db_name', '')) {
Expand Down