Revision 733

Date:
2018/10/31 12:36:38
Author:
ahitrov
Revision Log:
Sum difference check

Files:

Legend:

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

     
    224 224 if ( ref $opts->{order} && $opts->{order}->sum_discount > 0 ) {
    225 225 $discount = $opts->{order}->sum_discount / $opts->{order}->sum;
    226 226 }
    227 my $order_sum = int(($opts->{order}->sum - $opts->{order}->sum_discount) * 100);
    228 my $counted_sum = 0;
    227 229 foreach my $bi ( @{$opts->{basket}} ) {
    228 230 my $item = $bi->{item};
    229 231 next unless ref $item;
     
    238 240 taxSum => ($price * $bi->number) * $TAX_NDS{$self->{tax_nds}},
    239 241 };
    240 242 push @$positions, $pos;
    243 $counted_sum += $pos->{priceSum};
    241 244 }
    245 # Может быть разница в копейках между итоговой суммой и суммой по товарам. Её необходимо устранить
    246 my $diff = $counted_sum - $order_sum;
    247 if ( $diff != 0 ) {
    248 foreach my $pos ( @$positions ) {
    249 if ( $pos->{quantity} == 1 && ($pos->{priceSum} + $diff) > 0 ) {
    250 $pos->{price} += $diff;
    251 $pos->{priceSum} += $diff;
    252 $diff = 0;
    253 last;
    254 }
    255 }
    256 if ( $diff != 0 ) {
    257 my $pos = $positions->[-1];
    258 $pos->{priceSum} += $diff;
    259 if ( int($diff / $pos->{quantity}) > 1 ) {
    260 $pos->{price} += int($diff / $pos->{quantity});
    261 }
    262 }
    263 }
    242 264 unless ( @$positions ) {
    243 265 $self->{result}{error} = 'Cписок товарных позиций в заказе неверный. Возможно, в состав корзины не включены товары';
    244 266 return $self;