Revision 703

Date:
2018/08/15 22:35:46
Author:
ahitrov
Revision Log:
Receipt forming

Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/money/lib/money/Provider/Dreamkas.pm

     
    217 217
    218 218 if ( exists $opts->{basket} && ref $opts->{basket} eq 'ARRAY' ) {
    219 219 my $positions = [];
    220 my $discount = 0;
    221 if ( ref $opts->{order} && $opts->{order}->sum_discount > 0 ) {
    222 $discount = $opts->{order}->sum_discount / $opts->{order}->sum;
    223 }
    220 224 foreach my $bi ( @{$opts->{basket}} ) {
    221 225 my $item = $bi->{item};
    222 226 next unless ref $item;
    223 my $price = int($bi->{item}->price * 100);
    227 my $price = int(($bi->{item}->price - $discount * $bi->{item}->price) * 100);
    224 228 my $pos = {
    225 229 name => $bi->name,
    226 230 type => 'COUNTABLE',
     
    233 237 push @$positions, $pos;
    234 238 }
    235 239 unless ( @$positions ) {
    236 $self->{result}{error} = 'Cписок товарных позиций в заказе неверный. Возможно, в состав корзины не включенны товары';
    240 $self->{result}{error} = 'Cписок товарных позиций в заказе неверный. Возможно, в состав корзины не включены товары';
    237 241 return $self;
    238 242 }
    243 if ( ref $opts->{order} && $opts->{order}->sum_delivery > 0 ) {
    244 my $price = int($opts->{order}->sum_delivery * 100);
    245 my $pos = {
    246 name => 'Доставка',
    247 type => 'COUNTABLE',
    248 quantity => 1,
    249 price => $price,
    250 priceSum => $price,
    251 tax => $self->{tax_nds},
    252 taxSum => $price * $TAX_NDS{$self->{tax_nds}},
    253 };
    254 push @$positions, $pos;
    255 }
    239 256 $data->{positions} = $positions;
    240 257 } elsif ( exists $opts->{positions} && ref $opts->{positions} eq 'ARRAY' && @{$opts->{positions}} ) {
    241 258 $data->{positions} = $opts->{positions};
     
    270 287
    271 288 # Заполняем параметры оплаты: total и payments
    272 289 if ( exists $opts->{order} && ref $opts->{order} eq 'webshop::Order' ) {
    273 $data->{total}{priceSum} = int($opts->{order}->sum_total * 10);
    290 $data->{total}{priceSum} = int($opts->{order}->sum_total * 100);
    274 291 } else {
    275 292 if ( $opts->{total} ) {
    276 293 $data->{total}{priceSum} = $opts->{total};
     
    281 298 return $self;
    282 299 }
    283 300 $data->{payments}{sum} = $data->{total}{priceSum};
    284 $MR->sum( $data->{total}{priceSum} );
    301 $MR->sum( sprintf("%.2f", $data->{total}{priceSum} / 100) );
    285 302 if ( exists $opts->{payment_type} && $opts->{payment_type} eq 'CASH' ) {
    286 303 $data->{payments}{type} = 'CASH';
    287 304 }
     
    289 306 my $api_url = 'receipts';
    290 307
    291 308 $self->_MakeRequest( $api_url, 'post', $data );
    309 warn Data::Dumper::Dumper( $self->{result} ) if $DEBUG;
    292 310 if ( $self->{result}{code} == 202 || $self->{result}{code} == 200 ) {
    293 311 $MR->success( $OP_STATUS{$self->{result}{content}{status}} );
    294 312 $MR->session_id( $self->{result}{content}{id} );
     
    356 374 my $api_url = 'operations/'.$MR->session_id;
    357 375
    358 376 $self->_MakeRequest( $api_url, 'get' );
    377 warn Data::Dumper::Dumper( $self->{result} ) if $DEBUG;
    359 378 if ( $self->{result}{code} == 200 ) {
    360 379 $MR->success( $OP_STATUS{$self->{result}{content}{status}} );
    361 380 $MR->store;